diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-04-01 16:16:23 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-04-01 16:16:51 -0700 |
commit | d12d8ec9d728b0ce148f5a5caa68c858ef180d30 (patch) | |
tree | 5d980402593b9fede13d01367e720068eb5fd638 /builtin | |
parent | 6cb0186a41335f5e82d1e91abf4ce70938d0a020 (diff) | |
parent | 0cb6ad3c3d8e9c738686ef8dc6f173f725e509bc (diff) | |
download | git-d12d8ec9d728b0ce148f5a5caa68c858ef180d30.tar.gz git-d12d8ec9d728b0ce148f5a5caa68c858ef180d30.tar.xz |
Merge "checkout ambiguous ref bugfix" into maint
* commit '0cb6ad3':
checkout: fix bug with ambiguous refs
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/checkout.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index cd7f56e6c..e98576f22 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -678,7 +678,7 @@ static const char *unique_tracking_name(const char *name) int cmd_checkout(int argc, const char **argv, const char *prefix) { struct checkout_opts opts; - unsigned char rev[20]; + unsigned char rev[20], branch_rev[20]; const char *arg; struct branch_info new; struct tree *source_tree = NULL; @@ -832,18 +832,21 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) argc--; new.name = arg; - if ((new.commit = lookup_commit_reference_gently(rev, 1))) { - setup_branch_path(&new); + setup_branch_path(&new); - if ((check_ref_format(new.path) == CHECK_REF_FORMAT_OK) && - resolve_ref(new.path, rev, 1, NULL)) - ; - else - new.path = NULL; + if (check_ref_format(new.path) == CHECK_REF_FORMAT_OK && + resolve_ref(new.path, branch_rev, 1, NULL)) + hashcpy(rev, branch_rev); + else + new.path = NULL; /* not an existing branch */ + + if (!(new.commit = lookup_commit_reference_gently(rev, 1))) { + /* not a commit */ + source_tree = parse_tree_indirect(rev); + } else { parse_commit(new.commit); source_tree = new.commit->tree; - } else - source_tree = parse_tree_indirect(rev); + } if (!source_tree) /* case (1): want a tree */ die("reference is not a tree: %s", arg); |