summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/checkout.c23
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);