From: Duy Nguyen Date: Wed, 25 Sep 2013 13:22:39 GMT Subject: Re: [RFC/PATCH] checkout: allow dwim for branch creation for "git checkout $branch --" Message-ID: In-Reply-To: <1380113349-19838-1-git-send-email-Matthieu.Moy@imag.fr> On Wed, Sep 25, 2013 at 7:49 PM, Matthieu Moy 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. > @@ -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