git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git checkout -b origin/mybranch origin/mybranch

From
John Tapsell <johnflux@gmail.com>
Date
Mar 12, 2009, 16:58 UTC
Message-ID
<43d8ce650903120958n18baf6c0w9d083976b52d6e40@mail.gmail.com>
In-Reply-To
<20090312165153.GA28401@coredump.intra.peff.net>
2009/3/12 Jeff King <peff@peff.net>:
Show 38 quoted lines
> 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.
Previous: Jeff KingNext: Jeff King
Message 16 of 20 in “git checkout -b origin/mybranch origin/mybranch”
  1. John TapsellMar 12, 2009
  2. Sverre RabbelierMar 12, 2009
  3. Johannes SchindelinMar 12, 2009
  4. John TapsellMar 12, 2009
  5. Johannes SchindelinMar 12, 2009
  6. John TapsellMar 12, 2009
  7. Sverre RabbelierMar 12, 2009
  8. John TapsellMar 12, 2009
  9. Michael J GruberMar 13, 2009
  10. Pieter de BieMar 12, 2009
  11. Jeff KingMar 12, 2009
  12. John TapsellMar 12, 2009
  13. Jeff KingMar 12, 2009
  14. Pieter de BieMar 12, 2009
  15. Jeff KingMar 12, 2009
  16. John TapsellMar 12, 2009
  17. Jeff KingMar 12, 2009
  18. John TapsellMar 12, 2009
  19. John TapsellMar 12, 2009
  20. Junio C HamanoMar 12, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.