summaryrefslogtreecommitdiff
path: root/branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-02-14 07:08:05 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-02-14 07:46:28 (GMT)
commit8415d5c7ef63237f6efab0c9aef0b0fdbcbfda25 (patch)
tree08a6b8c58706bc47b78a29c73c91d5e8390fa7d4 /branch.c
parent5cd12b85fe8ff74f202a158511ead34e8aba584c (diff)
downloadgit-8415d5c7ef63237f6efab0c9aef0b0fdbcbfda25.zip
git-8415d5c7ef63237f6efab0c9aef0b0fdbcbfda25.tar.gz
git-8415d5c7ef63237f6efab0c9aef0b0fdbcbfda25.tar.bz2
Teach the "@{-1} syntax to "git branch"
This teaches the new "@{-1} syntax to refer to the previous branch to "git branch". After looking at somebody's faulty patch series on a topic branch too long, if you decide it is not worth merging, you can just say: $ git checkout master $ git branch -D @{-1} to get rid of it without having to type the name of the topic you now hate so much for wasting a lot of your time. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'branch.c')
-rw-r--r--branch.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/branch.c b/branch.c
index b1ac837..1f00e44 100644
--- a/branch.c
+++ b/branch.c
@@ -103,14 +103,22 @@ void create_branch(const char *head,
struct ref_lock *lock;
struct commit *commit;
unsigned char sha1[20];
- char *real_ref, ref[PATH_MAX], msg[PATH_MAX + 20];
+ char *real_ref, msg[PATH_MAX + 20];
+ struct strbuf ref = STRBUF_INIT;
int forcing = 0;
+ int len;
- snprintf(ref, sizeof ref, "refs/heads/%s", name);
- if (check_ref_format(ref))
+ len = strlen(name);
+ if (interpret_nth_last_branch(name, &ref) != len) {
+ strbuf_reset(&ref);
+ strbuf_add(&ref, name, len);
+ }
+ strbuf_splice(&ref, 0, 0, "refs/heads/", 11);
+
+ if (check_ref_format(ref.buf))
die("'%s' is not a valid branch name.", name);
- if (resolve_ref(ref, sha1, 1, NULL)) {
+ if (resolve_ref(ref.buf, sha1, 1, NULL)) {
if (!force)
die("A branch named '%s' already exists.", name);
else if (!is_bare_repository() && !strcmp(head, name))
@@ -142,7 +150,7 @@ void create_branch(const char *head,
die("Not a valid branch point: '%s'.", start_name);
hashcpy(sha1, commit->object.sha1);
- lock = lock_any_ref_for_update(ref, NULL, 0);
+ lock = lock_any_ref_for_update(ref.buf, NULL, 0);
if (!lock)
die("Failed to lock ref for update: %s.", strerror(errno));
@@ -162,6 +170,7 @@ void create_branch(const char *head,
if (write_ref_sha1(lock, sha1, msg) < 0)
die("Failed to write ref: %s.", strerror(errno));
+ strbuf_release(&ref);
free(real_ref);
}