aboutsummaryrefslogtreecommitdiff
path: root/builtin-branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-04-06 00:43:44 -0700
committerJunio C Hamano <gitster@pobox.com>2009-04-06 00:43:44 -0700
commitfbdc05661d9b732d06c47ccb3d5836d0d1b563e5 (patch)
treeb5e7e00ca449758d6244a382a27e9b967286787a /builtin-branch.c
parent03a39a91842cf745e5fc27dbd6485aad44d839a4 (diff)
parent3e262b95c50991de12cc5e180b72256561606a19 (diff)
downloadgit-fbdc05661d9b732d06c47ccb3d5836d0d1b563e5.tar.gz
git-fbdc05661d9b732d06c47ccb3d5836d0d1b563e5.tar.xz
Merge branch 'jc/name-branch'
* jc/name-branch: Don't permit ref/branch names to end with ".lock" check_ref_format(): tighten refname rules strbuf_check_branch_ref(): a helper to check a refname for a branch Fix branch -m @{-1} newname check-ref-format --branch: give Porcelain a way to grok branch shorthand strbuf_branchname(): a wrapper for branch name shorthands Rename interpret/substitute nth_last_branch functions Conflicts: Documentation/git-check-ref-format.txt
Diffstat (limited to 'builtin-branch.c')
-rw-r--r--builtin-branch.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/builtin-branch.c b/builtin-branch.c
index 07a440eeb..ca81d725c 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -121,11 +121,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
die("Couldn't look up commit object for HEAD");
}
for (i = 0; i < argc; i++, strbuf_release(&bname)) {
- int len = strlen(argv[i]);
-
- if (interpret_nth_last_branch(argv[i], &bname) != len)
- strbuf_add(&bname, argv[i], len);
-
+ strbuf_branchname(&bname, argv[i]);
if (kinds == REF_LOCAL_BRANCH && !strcmp(head, bname.buf)) {
error("Cannot delete the branch '%s' "
"which you are currently on.", bname.buf);
@@ -468,22 +464,27 @@ static void rename_branch(const char *oldname, const char *newname, int force)
struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;
unsigned char sha1[20];
struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT;
+ int recovery = 0;
if (!oldname)
die("cannot rename the current branch while not on any.");
- strbuf_addf(&oldref, "refs/heads/%s", oldname);
-
- if (check_ref_format(oldref.buf))
- die("Invalid branch name: %s", oldref.buf);
-
- strbuf_addf(&newref, "refs/heads/%s", newname);
+ if (strbuf_check_branch_ref(&oldref, oldname)) {
+ /*
+ * Bad name --- this could be an attempt to rename a
+ * ref that we used to allow to be created by accident.
+ */
+ if (resolve_ref(oldref.buf, sha1, 1, NULL))
+ recovery = 1;
+ else
+ die("Invalid branch name: '%s'", oldname);
+ }
- if (check_ref_format(newref.buf))
- die("Invalid branch name: %s", newref.buf);
+ if (strbuf_check_branch_ref(&newref, newname))
+ die("Invalid branch name: '%s'", newname);
if (resolve_ref(newref.buf, sha1, 1, NULL) && !force)
- die("A branch named '%s' already exists.", newname);
+ die("A branch named '%s' already exists.", newref.buf + 11);
strbuf_addf(&logmsg, "Branch: renamed %s to %s",
oldref.buf, newref.buf);
@@ -492,6 +493,9 @@ static void rename_branch(const char *oldname, const char *newname, int force)
die("Branch rename failed");
strbuf_release(&logmsg);
+ if (recovery)
+ warning("Renamed a misnamed branch '%s' away", oldref.buf + 11);
+
/* no need to pass logmsg here as HEAD didn't really move */
if (!strcmp(oldname, head) && create_symref("HEAD", newref.buf, NULL))
die("Branch renamed to %s, but HEAD is not updated!", newname);