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 | docs: fix filter-branch subdir example for exotic repo names (diff) | |
parent | checkout: fix bug with ambiguous refs (diff) | |
download | tgif-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 cd7f56e6c4..e98576f22e 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); |