From: Junio C Hamano Date: Wed, 20 Jan 2010 03:30:06 +0000 (-0800) Subject: Fix "checkout A..." synonym for "checkout A...HEAD" on Windows X-Git-Tag: v1.7.0-rc0~51^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=72a144e213b67621a4c3305dd9a07a200917fbc9;p=git.git 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 --- diff --git a/builtin-checkout.c b/builtin-checkout.c index fe7c8584c..ad3c01fdd 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);