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

Re: [RFC/PATCH] checkout: allow dwim for branch creation for "git checkout $branch --"

From
Duy Nguyen <pclouds@gmail.com>
Date
Sep 25, 2013, 13:22 UTC
Message-ID
<CACsJy8AbBrVSz=p+ARxvR_QXtku1BxbtQPv7pz_QCveeUEtwCQ@mail.gmail.com>
In-Reply-To
<1380113349-19838-1-git-send-email-Matthieu.Moy@imag.fr>
On Wed, Sep 25, 2013 at 7:49 PM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
>  static int parse_branchname_arg(int argc, const char **argv,
>                                 int dwim_new_local_branch_ok,
>                                 struct branch_info *new,

You may want to update the big comment block about all cases at the beginning of this function.

Show 20 quoted lines
> @@ -916,20 +924,28 @@ static int parse_branchname_arg(int argc, const char **argv,
>         if (!strcmp(arg, "-"))
>                 arg = "@{-1}";
>
> -       if (get_sha1_mb(arg, rev)) {
> -               if (has_dash_dash)          /* case (1) */
> -                       die(_("invalid reference: %s"), arg);
> -               if (dwim_new_local_branch_ok &&
> -                   !check_filename(NULL, arg) &&
> -                   argc == 1) {
> +       if (get_sha1_mb(arg, rev)) { /* case (1)? */
> +               int try_dwim = dwim_new_local_branch_ok;
> +
> +               if (check_filename(NULL, arg) && !has_dash_dash)
> +                       try_dwim = 0;
> +               /*
> +                * Accept "git checkout foo" and "git checkout foo --"
> +                * as candidates for dwim.
> +                */
> +               if (!(argc == 1 && !has_dash_dash) &&

has_dash_dash is calculated as (argc > 1) && !strcmp(argv[1], "--"), so when argc == 1, the has_dash_dash must be zero, the "&& !has_dash_dash" is redundant. But it makes me wonder what we do with "git checkout abc def -- xyz". I think both old and new code do not see "--" as a separator like it should (and should also error about multiple refs given). Maybe something worth fixing too while you're updating this code.

> +                   !(argc == 2 && has_dash_dash))
> +                       try_dwim = 0;
> +
-- 
Duy
Previous: Matthieu MoyNext: Matthieu Moy
Message 2 of 7 in “checkout: allow dwim for branch creation for "git checkout $branch --"”
  1. checkout: allow dwim for branch creation for "git checkout $branch --"Matthieu Moy, Sep 25, 2013
  2. Duy NguyenSep 25, 2013
  3. Matthieu MoySep 25, 2013
  4. Duy NguyenSep 25, 2013
  5. Junio C HamanoOct 16, 2013
  6. Matthieu MoyOct 17, 2013
  7. Junio C HamanoOct 17, 2013

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.