From: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: "Branch exists" error while trying to rename a non-existing branch to an existing one
Date: Mon, 10 Jul 2017 19:44:31 +0530 [thread overview]
Message-ID: <1499696071.1647.2.camel@gmail.com> (raw)
In-Reply-To: <xmqqd1998mks.fsf@gitster.mtv.corp.google.com>
On Sun, 2017-07-09 at 11:57 -0700, Junio C Hamano wrote:
> This is borderline "meh" at least to me. An argument against a
> hypothetical version of Git that "fixes" your issue would be that no
> matter what the source of renaming is, as long as 'master' exists,
> "branch -m" shouldn't overwrite it, and it is a good thing to remind
> the user that 'master' exists and the user meant to rename it to
> something else.
>
I'm not against the fact of reminding the user about an existing
branch. I'm with the fact that, warn him when he really has to care
about a branch being overwritten i.e., when he tries to rename an
"existing" branch to one that refers to another existing branch.
I found this behaviour odd as I try to relate it with the 'mv' command.
It's behaviour is as follows,
$ ls
file some_file
$ mv nothing file
mv: cannot stat 'nothing': No such file or directory
If I haven't missed anything the following patch seems to fix the
problem,
diff --git a/builtin/branch.c b/builtin/branch.c
index 48a513a84..2869aaca8 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -476,7 +476,10 @@ static void rename_branch(const char *oldname, const char *newname, int force)
*/
clobber_head_ok = !strcmp(oldname, newname);
- validate_new_branchname(newname, &newref, force, clobber_head_ok);
+ if(ref_exists(oldref.buf))
+ validate_new_branchname(newname, &newref, force, clobber_head_ok);
+ else
+ die(_("Branch '%s' does not exist."), oldname);
reject_rebase_or_bisect_branch(oldref.buf);
--
Kaartic
prev parent reply other threads:[~2017-07-10 14:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-09 18:27 "Branch exists" error while trying to rename a non-existing branch to an existing one Kaartic Sivaraam
2017-07-09 18:57 ` Junio C Hamano
2017-07-10 14:14 ` Kaartic Sivaraam [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1499696071.1647.2.camel@gmail.com \
--to=kaarticsivaraam91196@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).