From 72a144e213b67621a4c3305dd9a07a200917fbc9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 19 Jan 2010 19:30:06 -0800 Subject: [PATCH] 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 --- builtin-checkout.c | 6 ++++-- 1 file 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); -- 2.11.4.GIT