Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

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

From: Duy Nguyen <hidden>
Date: 2016-06-15 22:58:53

On Wed, Sep 25, 2013 at 7:49 PM, Matthieu Moy [off-list ref] 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.
quoted hunk ↗ jump to hunk
@@ -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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help