summaryrefslogtreecommitdiff
path: root/branch.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2009-02-15 00:03:29 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2009-02-15 00:03:29 -0800
commit472e4744ad28dfa568a1a46e5268aa2babb7243b (patch)
tree4f10098f38d27bf77eef3a22e60e51c258ece7fb /branch.c
parentbash: fix misspelled 'git svn' option (diff)
parentTeach @{-1} to git merge (diff)
downloadtgif-472e4744ad28dfa568a1a46e5268aa2babb7243b.tar.xz
Merge branch 'jc/branch-previous'
* jc/branch-previous: Teach @{-1} to git merge Teach the "@{-1} syntax to "git branch"
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 b1ac837f3d..1f00e44deb 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);
}