git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 16:58:22 +0000	[thread overview]
Message-ID: <43d8ce650903120958n18baf6c0w9d083976b52d6e40@mail.gmail.com> (raw)
In-Reply-To: <20090312165153.GA28401@coredump.intra.peff.net>

2009/3/12 Jeff King <peff@peff.net>:
> On Thu, Mar 12, 2009 at 04:40:10PM +0000, Pieter de Bie wrote:
>
>>> I think the future-proofing is probably not worth the effort.
>>> Catching things that are ambiguous _now_ will cover the "oops, I
>>> typed the wrong thing" case, which I think is really the issue.
>>
>> Exactly, that's the common case where things go wrong. I guess using
>> dwim_ref should be DWIM enough? :)
>
> Hmm. Yeah, I mispoke before: I should have said dwim_ref instead of
> resolve_ref (which doesn't dwym :) ).
>
> Here's a sloppy patch that I think does what you want; but it might make
> more sense to just iterate over ref_rev_parse_rules ourselves, as
> dwim_ref does more than we care about (and we should probably
> differentiate between "a branch already exists" and "this would make an
> ambiguous ref").
>
> ---
> diff --git a/branch.c b/branch.c
> index d20fb04..409f445 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -122,6 +122,7 @@ void create_branch(const char *head,
>        unsigned char sha1[20];
>        char *real_ref, msg[PATH_MAX + 20];
>        struct strbuf ref = STRBUF_INIT;
> +       char *junk;
>        int forcing = 0;
>        int len;
>
> @@ -135,7 +136,8 @@ 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 (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?

>                if (!force)
>                        die("A branch named '%s' already exists.", name);

>                        die("A branch named '%s' already exists (%s).", name, junk);

That would give  "A branched named 'origin/master' already exists
(refs/remotes/origin/master)"  right?

Dunno if it's worth it, just wondering.

  reply	other threads:[~2009-03-12 16:59 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 [this message]
2009-03-12 17:14                         ` Jeff King
2009-03-12 17:45                           ` John Tapsell
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=43d8ce650903120958n18baf6c0w9d083976b52d6e40@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).