Merge branch 'nd/checkout-disambiguation' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 29 Sep 2016 23:49:43 +0000 (16:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Sep 2016 23:49:44 +0000 (16:49 -0700)
"git checkout <word>" does not follow the usual disambiguation
rules when the <word> can be both a rev and a path, to allow
checking out a branch 'foo' in a project that happens to have a
file 'foo' in the working tree without having to disambiguate.
This was poorly documented and the check was incorrect when the
command was run from a subdirectory.

* nd/checkout-disambiguation:
checkout: fix ambiguity check in subdir
checkout.txt: document a common case that ignores ambiguation rules
checkout: add some spaces between code and comment

1  2 
builtin/checkout.c
diff --combined builtin/checkout.c
index afbff3e7903775caabf76399fa0066af9369a7f2,53c7284ffda0c0ce459ef7ab01e9c083a14d3ee8..0ad96786c9a257e2b4f3fd8325c68ae183c4b0f9
@@@ -154,8 -154,8 +154,8 @@@ static int check_stages(unsigned stages
        return 0;
  }
  
 -static int checkout_stage(int stage, struct cache_entry *ce, int pos,
 -                        struct checkout *state)
 +static int checkout_stage(int stage, const struct cache_entry *ce, int pos,
 +                        const struct checkout *state)
  {
        while (pos < active_nr &&
               !strcmp(active_cache[pos]->name, ce->name)) {
                return error(_("path '%s' does not have their version"), ce->name);
  }
  
 -static int checkout_merged(int pos, struct checkout *state)
 +static int checkout_merged(int pos, const struct checkout *state)
  {
        struct cache_entry *ce = active_cache[pos];
        const char *path = ce->name;
@@@ -985,7 -985,7 +985,7 @@@ static int parse_branchname_arg(int arg
                int recover_with_dwim = dwim_new_local_branch_ok;
  
                if (!has_dash_dash &&
-                   (check_filename(NULL, arg) || !no_wildcard(arg)))
+                   (check_filename(opts->prefix, arg) || !no_wildcard(arg)))
                        recover_with_dwim = 0;
                /*
                 * Accept "git checkout foo" and "git checkout foo --"
  
        if (!*source_tree)                   /* case (1): want a tree */
                die(_("reference is not a tree: %s"), arg);
-       if (!has_dash_dash) {/* case (3).(d) -> (1) */
+       if (!has_dash_dash) {   /* case (3).(d) -> (1) */
                /*
                 * Do not complain the most common case
                 *      git checkout branch
                 * it would be extremely annoying.
                 */
                if (argc)
-                       verify_non_filename(NULL, arg);
+                       verify_non_filename(opts->prefix, arg);
        } else {
                argcount++;
                argv++;