From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>,
Daniel Barkalow <barkalow@iabervon.org>
Subject: "checkout --track -b" broken? (with suggested fix)
Date: Thu, 16 Oct 2008 23:37:44 -0700 [thread overview]
Message-ID: <7vej2fohfr.fsf@gitster.siamese.dyndns.org> (raw)
Sorry for bringing up a potentially old issue, but I do not think the test
added by 9ed36cf (branch: optionally setup branch.*.merge from upstream
local branches, 2008-02-19) is correct. It does this:
test_expect_success \
'checkout w/--track from non-branch HEAD fails' '
git checkout -b delete-me master &&
rm .git/refs/heads/delete-me &&
test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
test_must_fail git checkout --track -b track'
It creates branch 'delete-me' at the tip of 'master' to check it out, and
then it manually deletes the branch. It expects "checkout --track -b track"
to fail because the current branch is broken and there is no way to set up
a tracking information for the new branch.
But I think this is bogus. The checkout fails not because of lack of
trackability (due to broken current _branch_), but because there is no
current _commit_ to branch from.
Jay CC'ed because 9ed36cf is his; Daniel CC'ed as branch.c was
originally his.
Here is an attempt to fix the test, which then revealed that the feature
the commit introduced is broken in the tip of 'maint'. Back when 9ed36cf
was written, test_must_fail was unavailable, and test_expect_failure meant
something different, so transplanting this on top of that old commit won't
reveal the breakage, but I strongly suspect that the feature was broken
from the very beginning.
The patch to branch.c is a quick fix for this issue. The resulting code
passes all the tests, but I am not very proud of hardcoding the "HEAD" in
the code. There must be a better way to do this.
branch.c | 4 +++-
t/t7201-co.sh | 11 +++++------
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git c/branch.c w/branch.c
index b1e59f2..6a75057 100644
--- c/branch.c
+++ w/branch.c
@@ -129,7 +129,9 @@ void create_branch(const char *head,
die("Cannot setup tracking information; starting point is not a branch.");
break;
case 1:
- /* Unique completion -- good */
+ /* Unique completion -- good, only if it is a real ref */
+ if (track == BRANCH_TRACK_EXPLICIT && !strcmp(real_ref, "HEAD"))
+ die("Cannot setup tracking information; starting point is not a branch.");
break;
default:
die("Ambiguous object name: '%s'.", start_name);
diff --git c/t/t7201-co.sh w/t/t7201-co.sh
index fbec70d..da1fbf8 100755
--- c/t/t7201-co.sh
+++ w/t/t7201-co.sh
@@ -330,12 +330,11 @@ test_expect_success \
test "$(git config branch.track2.merge)"
git config branch.autosetupmerge false'
-test_expect_success \
- 'checkout w/--track from non-branch HEAD fails' '
- git checkout -b delete-me master &&
- rm .git/refs/heads/delete-me &&
- test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&
- test_must_fail git checkout --track -b track'
+test_expect_success 'checkout w/--track from non-branch HEAD fails' '
+ git checkout master^0 &&
+ test_must_fail git symbolic-ref HEAD &&
+ test_must_fail git checkout --track -b track
+'
test_expect_success 'checkout an unmerged path should fail' '
rm -f .git/index &&
next reply other threads:[~2008-10-17 6:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-17 6:37 Junio C Hamano [this message]
2008-10-17 15:47 ` "checkout --track -b" broken? (with suggested fix) Daniel Barkalow
2008-10-17 23:57 ` Junio C Hamano
2008-10-18 2:17 ` Daniel Barkalow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vej2fohfr.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=barkalow@iabervon.org \
--cc=git@vger.kernel.org \
--cc=jaysoffian@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).