aboutsummaryrefslogtreecommitdiff
path: root/builtin/branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-12-13 22:53:08 -0800
committerJunio C Hamano <gitster@pobox.com>2011-12-13 22:53:08 -0800
commitb2dd02112052aff875e8dc7d12b9915c91feafe2 (patch)
tree575640076625dbc13dd950e78f8c0ab5f23e2b06 /builtin/branch.c
parenta96a89f7153150c7e59d5481dd22773173b5a877 (diff)
parent39bd6f726109942c6f77f59638f6763c9f00706c (diff)
downloadgit-b2dd02112052aff875e8dc7d12b9915c91feafe2.tar.gz
git-b2dd02112052aff875e8dc7d12b9915c91feafe2.tar.xz
Merge branch 'jn/branch-move-to-self'
* jn/branch-move-to-self: Allow checkout -B <current-branch> to update the current branch branch: allow a no-op "branch -M <current-branch> HEAD"
Diffstat (limited to 'builtin/branch.c')
-rw-r--r--builtin/branch.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index e1e486e4c..465ff6a51 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -570,6 +570,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)
struct strbuf oldref = STRBUF_INIT, newref = STRBUF_INIT, logmsg = STRBUF_INIT;
struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT;
int recovery = 0;
+ int clobber_head_ok;
if (!oldname)
die(_("cannot rename the current branch while not on any."));
@@ -585,7 +586,13 @@ static void rename_branch(const char *oldname, const char *newname, int force)
die(_("Invalid branch name: '%s'"), oldname);
}
- validate_new_branchname(newname, &newref, force, 0);
+ /*
+ * A command like "git branch -M currentbranch currentbranch" cannot
+ * cause the worktree to become inconsistent with HEAD, so allow it.
+ */
+ clobber_head_ok = !strcmp(oldname, newname);
+
+ validate_new_branchname(newname, &newref, force, clobber_head_ok);
strbuf_addf(&logmsg, "Branch: renamed %s to %s",
oldref.buf, newref.buf);
@@ -784,7 +791,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
if (kinds != REF_LOCAL_BRANCH)
die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
- force_create, reflog, track);
+ force_create, reflog, 0, track);
} else
usage_with_options(builtin_branch_usage, options);