{"thread":{"id":"24578","subject":"[PATCH] checkout: add a test for creating a new branch with regexp as a starting point","startedAt":"2010-07-29T22:01:11Z","lastAt":"2010-08-05T21:24:44Z","messageCount":17,"participants":["Dmitry V. Levin","Ævar Arnfjörð Bjarmason","Thomas Rast","Jonathan Nieder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"146737","messageId":"20100729220111.GA28176@wo.int.altlinux.org","threadId":"24578","inReplyTo":null,"subject":"[PATCH] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2010-07-29T22:01:11Z","receivedAt":"2010-07-29T22:01:11Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"Reported-by: Ivan Zakharyaschev <imz@altlinux.org>\nSigned-off-by: Dmitry V. Levin <ldv@altlinux.org>\n---\n\nThis is just a regression test for the bug.\n\n t/t2018-checkout-new-branch-by-regexp.sh |   22 ++++++++++++++++++++++\n 1 files changed, 22 insertions(+), 0 deletions(-)\n create mode 100755 t/t2018-checkout-new-branch-by-regexp.sh\n\ndiff --git a/t/t2018-checkout-new-branch-by-regexp.sh b/t/t2018-checkout-new-branch-by-regexp.sh\nnew file mode 100755\nindex 0000000..78e54c5\n--- /dev/null\n+++ b/t/t2018-checkout-new-branch-by-regexp.sh\n@@ -0,0 +1,22 @@\n+#!/bin/sh\n+\n+test_description='checkout -b new_branch :/regexp'\n+\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\techo a > a &&\n+\tgit add a &&\n+\ttest_tick &&\n+\tgit commit -m first &&\n+\techo b > b &&\n+\tgit add b &&\n+\ttest_tick &&\n+\tgit commit -m second\n+'\n+\n+test_expect_success checkout '\n+\tgit checkout -b new_branch :/first\n+'\n+\n+test_done\n\n-- \nldv\n"},{"id":"146744","messageId":"AANLkTi=Qf1OUmjkpL-6e8gT8MU9G=m37sxrdAoyj5=R0@mail.gmail.com","threadId":"24578","inReplyTo":"20100729220111.GA28176@wo.int.altlinux.org","subject":"Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-29T23:07:20Z","receivedAt":"2010-07-29T23:07:20Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Thu, Jul 29, 2010 at 22:01, Dmitry V. Levin <ldv@altlinux.org> wrote:\n> Reported-by: Ivan Zakharyaschev <imz@altlinux.org>\n> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>\n> ---\n>\n> This is just a regression test for the bug.\n\nThanks, always good to have more tests.\n\n>  t/t2018-checkout-new-branch-by-regexp.sh |   22 ++++++++++++++++++++++\n>  1 files changed, 22 insertions(+), 0 deletions(-)\n>  create mode 100755 t/t2018-checkout-new-branch-by-regexp.sh\n>\n> diff --git a/t/t2018-checkout-new-branch-by-regexp.sh b/t/t2018-checkout-new-branch-by-regexp.sh\n> new file mode 100755\n> index 0000000..78e54c5\n> --- /dev/null\n> +++ b/t/t2018-checkout-new-branch-by-regexp.sh\n> @@ -0,0 +1,22 @@\n> +#!/bin/sh\n> +\n> +test_description='checkout -b new_branch :/regexp'\n> +\n> +. ./test-lib.sh\n> +\n> +test_expect_success setup '\n> +       echo a > a &&\n> +       git add a &&\n> +       test_tick &&\n> +       git commit -m first &&\n> +       echo b > b &&\n> +       git add b &&\n> +       test_tick &&\n> +       git commit -m second\n> +'\n\nThis should use test_commit (see t/README), but...\n\n> +test_expect_success checkout '\n> +       git checkout -b new_branch :/first\n> +'\n> +\n> +test_done\n\n...it looks like this can just be added to the end of\nt2018-checkout-branch.sh instead of creating a new test. Creating a\nnew file just for a single test for such a simple feature is a bit of\nan overkill.\n"},{"id":"146745","messageId":"201007300136.13501.trast@student.ethz.ch","threadId":"24578","inReplyTo":"AANLkTi=Qf1OUmjkpL-6e8gT8MU9G=m37sxrdAoyj5=R0@mail.gmail.com","subject":"Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-07-29T23:36:13Z","receivedAt":"2010-07-29T23:36:13Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Ævar Arnfjörð Bjarmason wrote:\n> On Thu, Jul 29, 2010 at 22:01, Dmitry V. Levin <ldv@altlinux.org> wrote:\n> > +test_expect_success checkout '\n> > +       git checkout -b new_branch :/first\n> > +'\n> > +\n> > +test_done\n> \n> ...it looks like this can just be added to the end of\n> t2018-checkout-branch.sh instead of creating a new test. Creating a\n> new file just for a single test for such a simple feature is a bit of\n> an overkill.\n\nIt should also use test_expect_failure unless you expect to have a fix\nsoon, otherwise it would stop the test suite from running through.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"146767","messageId":"20100730084428.GA9577@wo.int.altlinux.org","threadId":"24578","inReplyTo":"201007300136.13501.trast@student.ethz.ch","subject":"Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2010-07-30T08:44:28Z","receivedAt":"2010-07-30T08:44:28Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"On Thu, Jul 29, 2010 at 11:07:20PM +0000, Ævar Arnfjörð Bjarmason wrote:\n> On Thu, Jul 29, 2010 at 22:01, Dmitry V. Levin wrote:\n[...]\n> > +test_expect_success setup '\n> > +       echo a > a &&\n> > +       git add a &&\n> > +       test_tick &&\n> > +       git commit -m first &&\n> > +       echo b > b &&\n> > +       git add b &&\n> > +       test_tick &&\n> > +       git commit -m second\n> > +'\n> \n> This should use test_commit (see t/README), but...\n\nThe peculiarity of this bug makes it impossible, because test_commit()\nalso creates a tag which spoils test conditions.\n\n> > +test_expect_success checkout '\n> > +       git checkout -b new_branch :/first\n> > +'\n> > +\n> > +test_done\n> \n> ...it looks like this can just be added to the end of\n> t2018-checkout-branch.sh instead of creating a new test. Creating a\n> new file just for a single test for such a simple feature is a bit of\n> an overkill.\n\nWell, I see no t2018-checkout-branch.sh yet.  What file do you suggest\nappending?\n\nOn Fri, Jul 30, 2010 at 01:36:13AM +0200, Thomas Rast wrote:\n> It should also use test_expect_failure unless you expect to have a fix\n> soon, otherwise it would stop the test suite from running through.\n\nOf course I'd like to have this bug fixed, but OK, let it be\ntest_expect_failure() for now.\n\n\n-- \nldv\n"},{"id":"146776","messageId":"AANLkTikan0hnUa-p-U1dfRKq+bORmrn7A3YTPOPe2N_k@mail.gmail.com","threadId":"24578","inReplyTo":"20100730084428.GA9577@wo.int.altlinux.org","subject":"Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-30T11:54:00Z","receivedAt":"2010-07-30T11:54:00Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Fri, Jul 30, 2010 at 08:44, Dmitry V. Levin <ldv@altlinux.org> wrote:\n> On Thu, Jul 29, 2010 at 11:07:20PM +0000, Ævar Arnfjörð Bjarmason wrote:\n>> On Thu, Jul 29, 2010 at 22:01, Dmitry V. Levin wrote:\n> [...]\n>> > +test_expect_success setup '\n>> > +       echo a > a &&\n>> > +       git add a &&\n>> > +       test_tick &&\n>> > +       git commit -m first &&\n>> > +       echo b > b &&\n>> > +       git add b &&\n>> > +       test_tick &&\n>> > +       git commit -m second\n>> > +'\n>>\n>> This should use test_commit (see t/README), but...\n>\n> The peculiarity of this bug makes it impossible, because test_commit()\n> also creates a tag which spoils test conditions.\n\nI didn't know that. It'd be good if the commit message or a comment\nindicated that. And actually, we should probably have a\ntest_commit_notag() then.\n\n>> > +test_expect_success checkout '\n>> > +       git checkout -b new_branch :/first\n>> > +'\n>> > +\n>> > +test_done\n>>\n>> ...it looks like this can just be added to the end of\n>> t2018-checkout-branch.sh instead of creating a new test. Creating a\n>> new file just for a single test for such a simple feature is a bit of\n>> an overkill.\n>\n> Well, I see no t2018-checkout-branch.sh yet.  What file do you suggest\n> appending?\n\nAh, t2018-checkout-branch.sh only exists on the pu branch, not\nmaster/next. It's probably worthwhile to patch it anyway rather than\nadding a new one.\n"},{"id":"146797","messageId":"20100730191357.GA2448@burratino","threadId":"24578","inReplyTo":"AANLkTikan0hnUa-p-U1dfRKq+bORmrn7A3YTPOPe2N_k@mail.gmail.com","subject":"When to use test_commit (Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point)","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-07-30T19:13:57Z","receivedAt":"2010-07-30T19:13:57Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ævar Arnfjörð Bjarmason wrote:\n\n> And actually, we should probably have a\n> test_commit_notag() then.\n\nI don’t know.  What’s so bad about using \"git commit\" directly?\n\nI often find myself using \"git commit\" in tests because test_commit\nimposes all the usual restrictions for a ref name on the commit\nmessage.  I would happily use an abbreviation for\n\n test_tick &&\n git commit -m \"something\" &&\n git tag something-else\n\nif available because I don’t like typing, but would that help the\nreader and test runner any?\n\n(That’s not a rhetorical question.  A patch that answers in the\npositive would be fine by me. ;-))\n"},{"id":"146800","messageId":"AANLkTimeQA2_fQ_f2pQchbo1coj3=mV9TRPnbET8SQ4F@mail.gmail.com","threadId":"24578","inReplyTo":"20100730191357.GA2448@burratino","subject":"Re: When to use test_commit (Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point)","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-30T20:20:40Z","receivedAt":"2010-07-30T20:20:40Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Fri, Jul 30, 2010 at 19:13, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Ævar Arnfjörð Bjarmason wrote:\n>\n>> And actually, we should probably have a\n>> test_commit_notag() then.\n>\n> I don’t know.  What’s so bad about using \"git commit\" directly?\n\nNothing, it's just easier to write and read the tests when we have and\nuse functions for these common operations.\n\n> I often find myself using \"git commit\" in tests because test_commit\n> imposes all the usual restrictions for a ref name on the commit\n> message.  I would happily use an abbreviation for\n>\n>  test_tick &&\n>  git commit -m \"something\" &&\n>  git tag something-else\n>\n> if available because I don’t like typing, but would that help the\n> reader and test runner any?\n\nMaybe just introduce a fourth argument to test_commit, to make it\n<message> [<file> [<contents> [<tagname>]] instead of <message>\n[<file> [<contents>]] ?\n"},{"id":"146808","messageId":"20100731001845.GA24129@wo.int.altlinux.org","threadId":"24578","inReplyTo":"AANLkTimeQA2_fQ_f2pQchbo1coj3=mV9TRPnbET8SQ4F@mail.gmail.com","subject":"[PATCH 1/2] test-lib.sh: introduce 4th argument to test_commit() specifying a tag name","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2010-07-31T00:18:46Z","receivedAt":"2010-07-31T00:18:46Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"When fourth argument to test_commit() is specified, use it as a tag\nname, unless it equals to empty string.  In the latter case, skip tag\ncreation.\n\nSuggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nSigned-off-by: Dmitry V. Levin <ldv@altlinux.org>\n---\n t/test-lib.sh |    8 +++++---\n 1 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 367f053..a203383 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -277,10 +277,12 @@ test_tick () {\n \texport GIT_COMMITTER_DATE GIT_AUTHOR_DATE\n }\n \n-# Call test_commit with the arguments \"<message> [<file> [<contents>]]\"\n+# Call test_commit with the arguments\n+# \"<message> [<file> [<contents> [<tagname>]]]\"\n #\n # This will commit a file with the given contents and the given commit\n-# message.  It will also add a tag with <message> as name.\n+# message.  It will also add a tag with the given name unless the latter\n+# is the empty string.\n #\n # Both <file> and <contents> default to <message>.\n \n@@ -290,7 +292,7 @@ test_commit () {\n \tgit add \"$file\" &&\n \ttest_tick &&\n \tgit commit -m \"$1\" &&\n-\tgit tag \"$1\"\n+\tif test -n \"${4-$1}\"; then git tag \"${4-$1}\"; fi\n }\n \n # Call test_merge with the arguments \"<message> <commit>\", where <commit>\n\n\n-- \nldv\n"},{"id":"146809","messageId":"20100731001919.GB24129@wo.int.altlinux.org","threadId":"24578","inReplyTo":"AANLkTimeQA2_fQ_f2pQchbo1coj3=mV9TRPnbET8SQ4F@mail.gmail.com","subject":"[PATCH 2/2] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2010-07-31T00:19:20Z","receivedAt":"2010-07-31T00:19:20Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"Reported-by: Ivan Zakharyaschev <imz@altlinux.org>\nSigned-off-by: Dmitry V. Levin <ldv@altlinux.org>\n---\n t/t2018-checkout-branch.sh |   13 +++++++++++++\n 1 files changed, 13 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh\nindex 1caffea..4d26b2a 100755\n--- a/t/t2018-checkout-branch.sh\n+++ b/t/t2018-checkout-branch.sh\n@@ -118,7 +118,20 @@ test_expect_success 'checkout -b to an existing branch fails' '\n \ttest_must_fail do_checkout branch2 $HEAD2\n '\n \n+test_expect_failure 'checkout -b new_branch :/regexp' '\n+\t# clean up from previous test\n+\tgit reset --hard &&\n+\n+\tdo_checkout old_regexp_branch branch1 &&\n+\ttest_commit first '' '' '' &&\n+\ttest_commit second '' '' '' &&\n+\n+\tdo_checkout new_regexp_branch :/first\n+'\n+\n test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '\n+\t# clean up from previous test\n+\tgit reset --hard &&\n \tgit checkout branch1 &&\n \n \tdo_checkout branch2 \"\" -B\n\n\n-- \nldv\n"},{"id":"146810","messageId":"AANLkTik3KBCh6Xn8r8odfdEfH=1Uf1bMKW6ic4UQPRsw@mail.gmail.com","threadId":"24578","inReplyTo":"20100731001845.GA24129@wo.int.altlinux.org","subject":"Re: [PATCH 1/2] test-lib.sh: introduce 4th argument to test_commit() specifying a tag name","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-31T00:39:43Z","receivedAt":"2010-07-31T00:39:43Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Jul 31, 2010 at 00:18, Dmitry V. Levin <ldv@altlinux.org> wrote:\n> When fourth argument to test_commit() is specified, use it as a tag\n> name, unless it equals to empty string.  In the latter case, skip tag\n> creation.\n\nLooks good, mostly.\n\n> Suggested-by: Ęvar Arnfjörš Bjarmason <avarab@gmail.com>\n\nSeems like you sent a ISO-8859-1 E-Mail with UTF-8 content.\n\nMy name also doubles as a UUID and a UTF-8 canary, you see.\n\n> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>\n> ---\n>  t/test-lib.sh |    8 +++++---\n>  1 files changed, 5 insertions(+), 3 deletions(-)\n>\n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index 367f053..a203383 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -277,10 +277,12 @@ test_tick () {\n>        export GIT_COMMITTER_DATE GIT_AUTHOR_DATE\n>  }\n>\n> -# Call test_commit with the arguments \"<message> [<file> [<contents>]]\"\n> +# Call test_commit with the arguments\n> +# \"<message> [<file> [<contents> [<tagname>]]]\"\n>  #\n>  # This will commit a file with the given contents and the given commit\n> -# message.  It will also add a tag with <message> as name.\n> +# message.  It will also add a tag with the given name unless the latter\n> +# is the empty string.\n\nYou should also patch t/README, which documents this function.\n\n>  # Both <file> and <contents> default to <message>.\n>\n> @@ -290,7 +292,7 @@ test_commit () {\n>        git add \"$file\" &&\n>        test_tick &&\n>        git commit -m \"$1\" &&\n> -       git tag \"$1\"\n> +       if test -n \"${4-$1}\"; then git tag \"${4-$1}\"; fi\n\nThis is just a nit, but I'd write this on 4 lines:\n\nif test..\nthen\n    git tag\nfi\n"},{"id":"146811","messageId":"AANLkTin11hHryAbJiOkiBH5TfpPbKREJK-ekWkd4fDhw@mail.gmail.com","threadId":"24578","inReplyTo":"20100731001919.GB24129@wo.int.altlinux.org","subject":"Re: [PATCH 2/2] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-31T00:44:00Z","receivedAt":"2010-07-31T00:44:00Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Jul 31, 2010 at 00:19, Dmitry V. Levin <ldv@altlinux.org> wrote:\n> Reported-by: Ivan Zakharyaschev <imz@altlinux.org>\n> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>\n> ---\n>  t/t2018-checkout-branch.sh |   13 +++++++++++++\n>  1 files changed, 13 insertions(+), 0 deletions(-)\n>\n> diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh\n> index 1caffea..4d26b2a 100755\n> --- a/t/t2018-checkout-branch.sh\n> +++ b/t/t2018-checkout-branch.sh\n> @@ -118,7 +118,20 @@ test_expect_success 'checkout -b to an existing branch fails' '\n>        test_must_fail do_checkout branch2 $HEAD2\n>  '\n>\n> +test_expect_failure 'checkout -b new_branch :/regexp' '\n> +       # clean up from previous test\n> +       git reset --hard &&\n> +\n> +       do_checkout old_regexp_branch branch1 &&\n> +       test_commit first '' '' '' &&\n> +       test_commit second '' '' '' &&\n\nShould note in the commit message or a comment that this test needs to\nnot create a tag, in case someone wonders down the line what the '' ''\n'' ASCII art is all about :)\n\nLooks good otherwise, thanks for patching test_commit.\n"},{"id":"146820","messageId":"20100731014449.GA19956@wo.int.altlinux.org","threadId":"24578","inReplyTo":"AANLkTin11hHryAbJiOkiBH5TfpPbKREJK-ekWkd4fDhw@mail.gmail.com","subject":"[PATCH 2/2 v2] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2010-07-31T01:44:49Z","receivedAt":"2010-07-31T01:44:49Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"Reported-by: Ivan Zakharyaschev <imz@altlinux.org>\nSigned-off-by: Dmitry V. Levin <ldv@altlinux.org>\n---\n t/t2018-checkout-branch.sh |   25 +++++++++++++++++++++----\n 1 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh\nindex 1caffea..6ada870 100755\n--- a/t/t2018-checkout-branch.sh\n+++ b/t/t2018-checkout-branch.sh\n@@ -4,12 +4,13 @@ test_description='checkout '\n \n . ./test-lib.sh\n \n-# Arguments: <branch> <sha> [<checkout options>]\n+# Arguments: <branch> <start_point> [<checkout options>]\n #\n # Runs \"git checkout\" to switch to <branch>, testing that\n #\n #   1) we are on the specified branch, <branch>;\n-#   2) HEAD is <sha>; if <sha> is not specified, the old HEAD is used.\n+#   2) HEAD points to the same commit as <start_point> does;\n+#      if <start_point> is not specified, the old HEAD is used.\n #\n # If <checkout options> is not specified, \"git checkout\" is run with -b.\n do_checkout() {\n@@ -17,7 +18,8 @@ do_checkout() {\n \texp_ref=\"refs/heads/$exp_branch\" &&\n \n \t# if <sha> is not specified, use HEAD.\n-\texp_sha=${2:-$(git rev-parse --verify HEAD)} &&\n+\tstart_point=${2:-HEAD}\n+\texp_sha=$(git rev-parse --verify $start_point) &&\n \n \t# default options for git checkout: -b\n \tif [ -z \"$3\" ]; then\n@@ -26,7 +28,7 @@ do_checkout() {\n \t\topts=\"$3\"\n \tfi\n \n-\tgit checkout $opts $exp_branch $exp_sha &&\n+\tgit checkout $opts $exp_branch $start_point &&\n \n \ttest $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&\n \ttest $exp_sha = $(git rev-parse --verify HEAD)\n@@ -118,7 +120,22 @@ test_expect_success 'checkout -b to an existing branch fails' '\n \ttest_must_fail do_checkout branch2 $HEAD2\n '\n \n+test_expect_failure 'checkout -b new_branch :/regexp' '\n+\t# clean up from previous test\n+\tgit reset --hard &&\n+\n+\tdo_checkout old_regexp_branch branch1 &&\n+\t# The first commit in this test should not be referenced by\n+\t# other branches or tags.\n+\ttest_commit first a a \"\" &&\n+\ttest_commit second &&\n+\n+\tdo_checkout new_regexp_branch :/first\n+'\n+\n test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '\n+\t# clean up from previous test\n+\tgit reset --hard &&\n \tgit checkout branch1 &&\n \n \tdo_checkout branch2 \"\" -B\n-- \n1.7.2.1\n"},{"id":"146821","messageId":"20100731015601.GB19956@wo.int.altlinux.org","threadId":"24578","inReplyTo":"AANLkTik3KBCh6Xn8r8odfdEfH=1Uf1bMKW6ic4UQPRsw@mail.gmail.com","subject":"[PATCH 1/2 v2] test-lib.sh: introduce 4th argument to test_commit() specifying a tag name","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2010-07-31T01:56:01Z","receivedAt":"2010-07-31T01:56:01Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"When fourth argument to test_commit() is specified, use it as a tag\nname, unless it equals to empty string.  In the latter case, skip tag\ncreation.\n\nSuggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nSigned-off-by: Dmitry V. Levin <ldv@altlinux.org>\n---\n t/README      |    8 ++++----\n t/test-lib.sh |   11 ++++++++---\n 2 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/t/README b/t/README\nindex 0d1183c..18f5810 100644\n--- a/t/README\n+++ b/t/README\n@@ -388,13 +388,13 @@ library for your script to use.\n    committer times to defined stated.  Subsequent calls will\n    advance the times by a fixed amount.\n \n- - test_commit <message> [<filename> [<contents>]]\n+ - test_commit <message> [<filename> [<contents> [<tagname>]]]\n \n    Creates a commit with the given message, committing the given\n    file with the given contents (default for both is to reuse the\n-   message string), and adds a tag (again reusing the message\n-   string as name).  Calls test_tick to make the SHA-1s\n-   reproducible.\n+   message string), and adds a tag with the given name (default again\n+   is to reuse the message string as name) unless this name is the\n+   empty string.  Calls test_tick to make the SHA-1s reproducible.\n \n  - test_merge <message> <commit-or-tag>\n \ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex e5523dd..ebb6215 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -277,10 +277,12 @@ test_tick () {\n \texport GIT_COMMITTER_DATE GIT_AUTHOR_DATE\n }\n \n-# Call test_commit with the arguments \"<message> [<file> [<contents>]]\"\n+# Call test_commit with the arguments\n+# \"<message> [<file> [<contents> [<tagname>]]]\"\n #\n # This will commit a file with the given contents and the given commit\n-# message.  It will also add a tag with <message> as name.\n+# message.  It will also add a tag with the given name unless the latter\n+# is the empty string.\n #\n # Both <file> and <contents> default to <message>.\n \n@@ -290,7 +292,10 @@ test_commit () {\n \tgit add \"$file\" &&\n \ttest_tick &&\n \tgit commit -m \"$1\" &&\n-\tgit tag \"$1\"\n+\tif test -n \"${4-$1}\"\n+\tthen\n+\t\tgit tag \"${4-$1}\"\n+\tfi\n }\n \n # Call test_merge with the arguments \"<message> <commit>\", where <commit>\n\n\n-- \nldv\n"},{"id":"146853","messageId":"AANLkTi=gNtq1fd4_QPZZX4+nLqUfVJhSA2zA_=0gfKLF@mail.gmail.com","threadId":"24578","inReplyTo":"20100731015601.GB19956@wo.int.altlinux.org","subject":"Re: [PATCH 1/2 v2] test-lib.sh: introduce 4th argument to test_commit() specifying a tag name","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-31T10:23:15Z","receivedAt":"2010-07-31T10:23:15Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Jul 31, 2010 at 01:56, Dmitry V. Levin <ldv@altlinux.org> wrote:\n> When fourth argument to test_commit() is specified, use it as a tag\n> name, unless it equals to empty string.  In the latter case, skip tag\n> creation.\n>\n> Suggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>\n> ---\n>  t/README      |    8 ++++----\n>  t/test-lib.sh |   11 ++++++++---\n>  2 files changed, 12 insertions(+), 7 deletions(-)\n>\n> diff --git a/t/README b/t/README\n> index 0d1183c..18f5810 100644\n> --- a/t/README\n> +++ b/t/README\n> @@ -388,13 +388,13 @@ library for your script to use.\n>    committer times to defined stated.  Subsequent calls will\n>    advance the times by a fixed amount.\n>\n> - - test_commit <message> [<filename> [<contents>]]\n> + - test_commit <message> [<filename> [<contents> [<tagname>]]]\n>\n>    Creates a commit with the given message, committing the given\n>    file with the given contents (default for both is to reuse the\n> -   message string), and adds a tag (again reusing the message\n> -   string as name).  Calls test_tick to make the SHA-1s\n> -   reproducible.\n> +   message string), and adds a tag with the given name (default again\n> +   is to reuse the message string as name) unless this name is the\n> +   empty string.  Calls test_tick to make the SHA-1s reproducible.\n>\n>  - test_merge <message> <commit-or-tag>\n>\n> diff --git a/t/test-lib.sh b/t/test-lib.sh\n> index e5523dd..ebb6215 100644\n> --- a/t/test-lib.sh\n> +++ b/t/test-lib.sh\n> @@ -277,10 +277,12 @@ test_tick () {\n>        export GIT_COMMITTER_DATE GIT_AUTHOR_DATE\n>  }\n>\n> -# Call test_commit with the arguments \"<message> [<file> [<contents>]]\"\n> +# Call test_commit with the arguments\n> +# \"<message> [<file> [<contents> [<tagname>]]]\"\n>  #\n>  # This will commit a file with the given contents and the given commit\n> -# message.  It will also add a tag with <message> as name.\n> +# message.  It will also add a tag with the given name unless the latter\n> +# is the empty string.\n>  #\n>  # Both <file> and <contents> default to <message>.\n>\n> @@ -290,7 +292,10 @@ test_commit () {\n>        git add \"$file\" &&\n>        test_tick &&\n>        git commit -m \"$1\" &&\n> -       git tag \"$1\"\n> +       if test -n \"${4-$1}\"\n> +       then\n> +               git tag \"${4-$1}\"\n> +       fi\n>  }\n>\n>  # Call test_merge with the arguments \"<message> <commit>\", where <commit>\n\nThis one looks good, thanks.\n\nAcked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"},{"id":"146854","messageId":"AANLkTi=+60yK8A-bYT6ySFTxXxmCD9nD_LW1WX2GgDbm@mail.gmail.com","threadId":"24578","inReplyTo":"20100731014449.GA19956@wo.int.altlinux.org","subject":"Re: [PATCH 2/2 v2] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-31T10:24:13Z","receivedAt":"2010-07-31T10:24:13Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Jul 31, 2010 at 01:44, Dmitry V. Levin <ldv@altlinux.org> wrote:\n> Reported-by: Ivan Zakharyaschev <imz@altlinux.org>\n> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>\n> ---\n>  t/t2018-checkout-branch.sh |   25 +++++++++++++++++++++----\n>  1 files changed, 21 insertions(+), 4 deletions(-)\n>\n> diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh\n> index 1caffea..6ada870 100755\n> --- a/t/t2018-checkout-branch.sh\n> +++ b/t/t2018-checkout-branch.sh\n> @@ -4,12 +4,13 @@ test_description='checkout '\n>\n>  . ./test-lib.sh\n>\n> -# Arguments: <branch> <sha> [<checkout options>]\n> +# Arguments: <branch> <start_point> [<checkout options>]\n>  #\n>  # Runs \"git checkout\" to switch to <branch>, testing that\n>  #\n>  #   1) we are on the specified branch, <branch>;\n> -#   2) HEAD is <sha>; if <sha> is not specified, the old HEAD is used.\n> +#   2) HEAD points to the same commit as <start_point> does;\n> +#      if <start_point> is not specified, the old HEAD is used.\n>  #\n>  # If <checkout options> is not specified, \"git checkout\" is run with -b.\n>  do_checkout() {\n> @@ -17,7 +18,8 @@ do_checkout() {\n>        exp_ref=\"refs/heads/$exp_branch\" &&\n>\n>        # if <sha> is not specified, use HEAD.\n> -       exp_sha=${2:-$(git rev-parse --verify HEAD)} &&\n> +       start_point=${2:-HEAD}\n> +       exp_sha=$(git rev-parse --verify $start_point) &&\n>\n>        # default options for git checkout: -b\n>        if [ -z \"$3\" ]; then\n> @@ -26,7 +28,7 @@ do_checkout() {\n>                opts=\"$3\"\n>        fi\n>\n> -       git checkout $opts $exp_branch $exp_sha &&\n> +       git checkout $opts $exp_branch $start_point &&\n>\n>        test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&\n>        test $exp_sha = $(git rev-parse --verify HEAD)\n> @@ -118,7 +120,22 @@ test_expect_success 'checkout -b to an existing branch fails' '\n>        test_must_fail do_checkout branch2 $HEAD2\n>  '\n>\n> +test_expect_failure 'checkout -b new_branch :/regexp' '\n> +       # clean up from previous test\n> +       git reset --hard &&\n> +\n> +       do_checkout old_regexp_branch branch1 &&\n> +       # The first commit in this test should not be referenced by\n> +       # other branches or tags.\n> +       test_commit first a a \"\" &&\n> +       test_commit second &&\n> +\n> +       do_checkout new_regexp_branch :/first\n> +'\n> +\n>  test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '\n> +       # clean up from previous test\n> +       git reset --hard &&\n>        git checkout branch1 &&\n>\n>        do_checkout branch2 \"\" -B\n> --\n> 1.7.2.1\n\nLooks good, thanks.\n\nAcked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"},{"id":"146993","messageId":"7v1vaglo9w.fsf@alter.siamese.dyndns.org","threadId":"24578","inReplyTo":"201007300136.13501.trast@student.ethz.ch","subject":"Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-08-02T21:04:27Z","receivedAt":"2010-08-02T21:04:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> writes:\n\n>> > +test_expect_success checkout '\n>> > +       git checkout -b new_branch :/first\n>> > +'\n>> > +\n>> > +test_done\n>> \n>> ...it looks like this can just be added to the end of\n>> t2018-checkout-branch.sh instead of creating a new test. Creating a\n>> new file just for a single test for such a simple feature is a bit of\n>> an overkill.\n>\n> It should also use test_expect_failure unless you expect to have a fix\n> soon, otherwise it would stop the test suite from running through.\n\nI think this is an ancient bug from the very beginning of the \":/\"\nnotation.  Because it temporarily uses one bit in the object flags, but\nthe get_sha1_oneline() parser can be called multiple times, it tries to\nclear the flag bits it smudged at the end, but fails.\n\nThe basic pattern for traversing the ancestry while avoiding duplication\nis:\n\n    prepare commits you traverse from in \"list\";\n    while (list) {\n        commit = pop_most_recent_commit(&list, MARK);\n        try to use commit;\n    }\n\npop_most_recent_commit() removes a commit from the list, pushes parents of\nthe commit that are _not_ marked with any of the bits in the MARK to the\ngiven list, and returns that commit.\n\nWhile introducing the feature ':/', however, 28a4d94 (object name:\nintroduce ':/<oneline prefix>' notation, 2007-02-24) wanted to avoid\nleaving the mark used in the loop before leaving the function (which is a\nright thing to do), by doing this:\n\n    prepare commits you traverse from in \"list\";\n+   keep a copy of \"list\" in \"backup\";\n    while (list) {\n        commit = pop_most_recent_commit(&list, MARK);\n        try to use commit;\n    }\n+   for (commit in backup)\n+       clear_commit_marks(commit, MARK);\n\nwhich is wrong, as clear_commit_marks() will ignore if the starting commit\ndoes not have the MARK.\n\nI think the fix should be just as simple as this.  Essentially, X_SEEN\nmark means \"we have marked and placed this item on the list (so do not put\nit again back on the list when it appears as a parent of some other item)\"\nso marking commits we initially put on the list with the bit should be the\nright thing to do regardless of this clean-up business.\n\n sha1_name.c |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 4f2af8d..b935688 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -704,8 +704,10 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)\n \t\tdie(\"Invalid search pattern: %s\", prefix);\n \n \tfor_each_ref(handle_one_ref, &list);\n-\tfor (l = list; l; l = l->next)\n+\tfor (l = list; l; l = l->next) {\n \t\tcommit_list_insert(l->item, &backup);\n+\t\tl->item->object.flags |= ONELINE_SEEN;\n+\t}\n \twhile (list) {\n \t\tchar *p;\n \t\tstruct commit *commit;\n"},{"id":"147252","messageId":"20100805212444.GB12207@wo.int.altlinux.org","threadId":"24578","inReplyTo":"AANLkTi=+60yK8A-bYT6ySFTxXxmCD9nD_LW1WX2GgDbm@mail.gmail.com","subject":"Re: [PATCH 2/2 v3] checkout: add a test for creating a new branch with regexp as a starting point","fromName":"Dmitry V. Levin","fromEmail":"ldv@altlinux.org","sentAt":"2010-08-05T21:24:44Z","receivedAt":"2010-08-05T21:24:44Z","isPatch":true,"sender":{"key":"ldv@altlinux.org","avatar":"https://avatars.githubusercontent.com/u/5281408?v=4"},"body":"Reported-by: Ivan Zakharyaschev <imz@altlinux.org>\nSigned-off-by: Dmitry V. Levin <ldv@altlinux.org>\nAcked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\nThe only difference between v2 and v3 editions of this patch is that\ntest_expect_failure has been replaced with test_expect_success, because\nthe fix (jc/sha1-name-find-fix) is already available.\n\n t/t2018-checkout-branch.sh |   25 +++++++++++++++++++++----\n 1 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh\nindex 1caffea..13f7194 100755\n--- a/t/t2018-checkout-branch.sh\n+++ b/t/t2018-checkout-branch.sh\n@@ -4,12 +4,13 @@ test_description='checkout '\n \n . ./test-lib.sh\n \n-# Arguments: <branch> <sha> [<checkout options>]\n+# Arguments: <branch> <start_point> [<checkout options>]\n #\n # Runs \"git checkout\" to switch to <branch>, testing that\n #\n #   1) we are on the specified branch, <branch>;\n-#   2) HEAD is <sha>; if <sha> is not specified, the old HEAD is used.\n+#   2) HEAD points to the same commit as <start_point> does;\n+#      if <start_point> is not specified, the old HEAD is used.\n #\n # If <checkout options> is not specified, \"git checkout\" is run with -b.\n do_checkout() {\n@@ -17,7 +18,8 @@ do_checkout() {\n \texp_ref=\"refs/heads/$exp_branch\" &&\n \n \t# if <sha> is not specified, use HEAD.\n-\texp_sha=${2:-$(git rev-parse --verify HEAD)} &&\n+\tstart_point=${2:-HEAD}\n+\texp_sha=$(git rev-parse --verify $start_point) &&\n \n \t# default options for git checkout: -b\n \tif [ -z \"$3\" ]; then\n@@ -26,7 +28,7 @@ do_checkout() {\n \t\topts=\"$3\"\n \tfi\n \n-\tgit checkout $opts $exp_branch $exp_sha &&\n+\tgit checkout $opts $exp_branch $start_point &&\n \n \ttest $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&\n \ttest $exp_sha = $(git rev-parse --verify HEAD)\n@@ -118,7 +120,22 @@ test_expect_success 'checkout -b to an existing branch fails' '\n \ttest_must_fail do_checkout branch2 $HEAD2\n '\n \n+test_expect_success 'checkout -b new_branch :/regexp' '\n+\t# clean up from previous test\n+\tgit reset --hard &&\n+\n+\tdo_checkout old_regexp_branch branch1 &&\n+\t# The first commit in this test should not be referenced by\n+\t# other branches or tags.\n+\ttest_commit first a a \"\" &&\n+\ttest_commit second &&\n+\n+\tdo_checkout new_regexp_branch :/first\n+'\n+\n test_expect_success 'checkout -B to an existing branch resets branch to HEAD' '\n+\t# clean up from previous test\n+\tgit reset --hard &&\n \tgit checkout branch1 &&\n \n \tdo_checkout branch2 \"\" -B\n\n-- \nldv\n"}]}