Soeren Sonnenburg wrote:
> to reproduce (as run by a buildbot) do e.g.,
>
> mkdir foo && cd foo
> git init
> git fetch -t git://github.com/shogun-toolbox/shogun.git +master
> git reset --hard 72d1bdeb46bf0c63c9d59c940930f2dba1bb6111
> git branch -M master
Ah, here's another exception to the "it's usually not obvious what it
would mean to overwrite the current branch by another one" rule.
Namely:
git branch -M master master
is clearly meant to be a no-op, even if you are on the master branch.
And in the latter case, it can be abbreviated:
git branch -M master
This seems like a valuable exception to allow, because then "git
branch -M foo" would _always_ be allowed --- either 'foo' is not the
current branch, and it does the obvious thing, or 'foo' is the current
branch, and nothing happens.
Something like this (untested):
builtin/branch.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 009b713..d3a450d 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -568,6 +568,7 @@ static void rename_branch(const char *oldname, const char
*newname, int force)
unsigned char sha1[20];
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."));
@@ -583,7 +584,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) ? 1 : 0;
+
+ validate_new_branchname(newname, &newref, force, clobber_head_ok);
strbuf_addf(&logmsg, "Branch: renamed %s to %s",
oldref.buf, newref.buf);
--
1.7.7
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]