From: John Tapsell <johnflux@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Pieter de Bie <pdebie@ai.rug.nl>,
Sverre Rabbelier <srabbelier@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Git List <git@vger.kernel.org>
Subject: Re: git checkout -b origin/mybranch origin/mybranch
Date: Thu, 12 Mar 2009 17:45:56 +0000 [thread overview]
Message-ID: <43d8ce650903121045s74584d97o708d4f8fd2baf664@mail.gmail.com> (raw)
In-Reply-To: <20090312171420.GA2192@coredump.intra.peff.net>
2009/3/12 Jeff King <peff@peff.net>:
> On Thu, Mar 12, 2009 at 04:58:22PM +0000, John Tapsell wrote:
>
>> > - if (resolve_ref(ref.buf, sha1, 1, NULL)) {
>> > + if (dwim_ref(name, strlen(name), sha1, &junk)) {
>> > + free(junk);
>>
>> Presumably 'junk' is the resolved name? I wonder if it's worth
>> putting this info in the error message?
>
> Hey, I said it was sloppy, right? ;)
>
> Here's your suggestion, plus specifying which situation (existing branch
> or ambiguous ref) would occur. It would still need tests. But I'm
> curious to hear more opinions on this direction before cleaning it up
> much more (at the very least, it needs some tests).
I like :-) Just minor comments:
> --- a/branch.c
> +++ b/branch.c
> @@ -133,6 +133,7 @@ void create_branch(const char *head,
> unsigned char sha1[20];
> char *real_ref, msg[PATH_MAX + 20];
> struct strbuf ref = STRBUF_INIT;
> + char *existing;
Don't suppose you could set this NULL. Just in case dwim_ref doesn't
set &existing for whatever reason.
> int forcing = 0;
> int len;
>
> @@ -146,12 +147,18 @@ void create_branch(const char *head,
> if (check_ref_format(ref.buf))
> die("'%s' is not a valid branch name.", name);
>
> - if (resolve_ref(ref.buf, sha1, 1, NULL)) {
> - if (!force)
> - die("A branch named '%s' already exists.", name);
> + if (dwim_ref(name, strlen(name), sha1, &existing)) {
> + if (!force) {
> + if (!prefixcmp(existing, "refs/heads/"))
> + die("A branch named '%s' already exists.",
> + name);
> + die("Creating '%s' would be ambiguous with"
> + " the existing %s", name, existing);
Maybe put single quotes around the second %s, for consistency with the first?
> + }
> else if (!is_bare_repository() && !strcmp(head, name))
> die("Cannot force update the current branch.");
> forcing = 1;
> + free(existing);
> }
>
> real_ref = NULL;
>
next prev parent reply other threads:[~2009-03-12 17:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-12 11:36 git checkout -b origin/mybranch origin/mybranch John Tapsell
2009-03-12 11:40 ` Sverre Rabbelier
2009-03-12 11:43 ` Johannes Schindelin
2009-03-12 11:48 ` John Tapsell
2009-03-12 13:02 ` Johannes Schindelin
2009-03-12 13:18 ` John Tapsell
2009-03-12 13:43 ` Sverre Rabbelier
2009-03-12 14:14 ` John Tapsell
2009-03-13 14:08 ` Michael J Gruber
2009-03-12 15:21 ` Pieter de Bie
2009-03-12 15:37 ` Jeff King
2009-03-12 16:16 ` John Tapsell
2009-03-12 16:35 ` Jeff King
2009-03-12 16:40 ` Pieter de Bie
2009-03-12 16:51 ` Jeff King
2009-03-12 16:58 ` John Tapsell
2009-03-12 17:14 ` Jeff King
2009-03-12 17:45 ` John Tapsell [this message]
2009-03-12 16:45 ` John Tapsell
2009-03-12 18:31 ` Junio C Hamano
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=43d8ce650903121045s74584d97o708d4f8fd2baf664@mail.gmail.com \
--to=johnflux@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=pdebie@ai.rug.nl \
--cc=peff@peff.net \
--cc=srabbelier@gmail.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).