summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-01-19 19:30:06 -0800
committerJunio C Hamano <gitster@pobox.com>2010-01-19 19:30:06 -0800
commit72a144e213b67621a4c3305dd9a07a200917fbc9 (patch)
tree179c10ca4e642c0f15553c038c42bec1c468959b
parent230a4566382860fc26a3f8d578a41c6504cf865f (diff)
downloadgit-72a144e213b67621a4c3305dd9a07a200917fbc9.tar.gz
Fix "checkout A..." synonym for "checkout A...HEAD" on Windows
When switching to a different commit, we first see the named rev exists as a commit using lookup_commit_reference_gently(), and set new.path to a string "refs/heads/" followed by the name the user gave us (but after taking into special short-hands like @{-1} == "previous branch" and "@{upstream}" == "the branch we merge with" into account). If the resulting string names an existsing ref, then we are switching to that branch (and will be building new commits on top of it); otherwise we are detaching HEAD at that commit. When the "master..." syntax is used as a short-hand for "master...HEAD", we do want to detach HEAD at the merge base. However, on Windows, when asked if ".git/refs/heads/master..." exists, the filesystem happily says "it does" when ".git/refs/heads/master" exists. Work this issue around by first calling check_ref_format(new.path) to see if the string can possibly be a valid ref under "refs/heads/", before asking resolve_ref(). We used to run another lookup_commit_reference(rev) even though we know it succeeded and we have a good commit in new.commit already; this has been with us from 782c2d6 (Build in checkout, 2008-02-07), the first version we had "git checkout" implemented in C. Drop it. Noticed by Alex Riesen. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin-checkout.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c
index fe7c8584ca..ad3c01fdd9 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -745,8 +745,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
new.name = arg;
if ((new.commit = lookup_commit_reference_gently(rev, 1))) {
setup_branch_path(&new);
- if (resolve_ref(new.path, rev, 1, NULL))
- new.commit = lookup_commit_reference(rev);
+
+ if ((check_ref_format(new.path) == CHECK_REF_FORMAT_OK) &&
+ resolve_ref(new.path, rev, 1, NULL))
+ ;
else
new.path = NULL;
parse_commit(new.commit);