diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-01-28 15:00:27 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-01-28 15:00:27 -0800 |
commit | 8712b3cdb0495f5a56b91cd67e2697412447a886 (patch) | |
tree | 98dafb9b4f38617d73ef59c9085e01ee727af729 /builtin-checkout.c | |
parent | cd956c73a2cce6613a6cd19df6ccb9ff1b08f79a (diff) | |
parent | 73ff1a131b340633b2ec2a0e68490de721448f56 (diff) | |
download | git-8712b3cdb0495f5a56b91cd67e2697412447a886.tar.gz |
Merge branch 'tr/previous-branch'
* tr/previous-branch:
t1505: remove debugging cruft
Simplify parsing branch switching events in reflog
Introduce for_each_recent_reflog_ent().
interpret_nth_last_branch(): plug small memleak
Fix reflog parsing for a malformed branch switching entry
Fix parsing of @{-1}@{1}
interpret_nth_last_branch(): avoid traversing the reflog twice
checkout: implement "-" abbreviation, add docs and tests
sha1_name: support @{-N} syntax in get_sha1()
sha1_name: tweak @{-N} lookup
checkout: implement "@{-N}" shortcut name for N-th last branch
Conflicts:
sha1_name.c
Diffstat (limited to 'builtin-checkout.c')
-rw-r--r-- | builtin-checkout.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c index 6cdb320ae7..20b34ce6e1 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -351,8 +351,16 @@ struct branch_info { static void setup_branch_path(struct branch_info *branch) { struct strbuf buf = STRBUF_INIT; - strbuf_addstr(&buf, "refs/heads/"); - strbuf_addstr(&buf, branch->name); + int ret; + + if ((ret = interpret_nth_last_branch(branch->name, &buf)) + && ret == strlen(branch->name)) { + branch->name = xstrdup(buf.buf); + strbuf_splice(&buf, 0, 0, "refs/heads/", 11); + } else { + strbuf_addstr(&buf, "refs/heads/"); + strbuf_addstr(&buf, branch->name); + } branch->path = strbuf_detach(&buf, NULL); } @@ -661,6 +669,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) arg = argv[0]; has_dash_dash = (argc > 1) && !strcmp(argv[1], "--"); + if (!strcmp(arg, "-")) + arg = "@{-1}"; + if (get_sha1(arg, rev)) { if (has_dash_dash) /* case (1) */ die("invalid reference: %s", arg); |