]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add: simplify -u/-A without pathspec
authorJunio C Hamano <gitster@pobox.com>
Sun, 25 Oct 2015 02:31:11 +0000 (19:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 25 Oct 2015 02:32:47 +0000 (19:32 -0700)
Since Git 2.0, "add -u" and "add -A" run from a subdirectory without
any pathspec mean "everything in the working tree" (before 2.0, they
were limited to the current directory).  The limiting to the current
directory was implemented by inserting "." to the command line when
the end user did not give us any pathspec.  At 2.0, we updated the
code to insert ":/" (instead of '.') to consider everything from the
top-level, by using a pathspec magic "top".

The call to parse_pathspec() using the command line arguments is,
however, made with PATHSPEC_PREFER_FULL option since 5a76aff1 (add:
convert to use parse_pathspec, 2013-07-14), which predates Git 2.0.
In retrospect, there was no need to turn "adding . to limit to the
directory" into "adding :/ to unlimit to everywhere" in Git 2.0;
instead we could just have done "if there is no pathspec on the
command line, just let it be".  The parse_pathspec() then would give
us a pathspec that matches everything and all is well.

Incidentally such a simplification also fixes a corner case bug that
stems from the fact that ":/" does not necessarily mean any magic.
A user would say "git --literal-pathspecs add -u :/" from the
command line when she has a directory ':' and wants to add
everything in it (and she knows that her :/ will be taken as
'everything under the sun' magic pathspec unless she disables the
magic with --literal-pathspecs).  The internal use of ':/' would
behave the same way as such an explicitly given ":/" when run with
"--literal-pathspecs", and will not add everything under the sun as
the code originally intended.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
t/t2200-add-update.sh
t/t2202-add-addremove.sh

index 459208a326cd4cebfa813168d81a06c27fc54fc5..06ad3653f0105b411d5effe219105305cb47b843 100644 (file)
@@ -336,14 +336,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        if (!show_only && ignore_missing)
                die(_("Option --ignore-missing can only be used together with --dry-run"));
 
-       if ((0 < addremove_explicit || take_worktree_changes) && !argc) {
-               static const char *whole[2] = { ":/", NULL };
-               argc = 1;
-               argv = whole;
-       }
-
        add_new_files = !take_worktree_changes && !refresh_only;
-       require_pathspec = !take_worktree_changes;
+       require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
 
        newfd = hold_locked_index(&lock_file, 1);
 
index e16b15d3e5784eb3c6423318142cb91fe3a58601..314c73c5a708fda8f39e7a86bf3db0329191d7a7 100755 (executable)
@@ -84,6 +84,8 @@ test_expect_success 'non-qualified update in subdir updates from the root' '
        (
                cd dir1 &&
                echo even more >>sub2 &&
+               git --literal-pathspecs add -u &&
+               echo even more >>sub2 &&
                git add -u
        ) &&
        : >expect &&
index fc8b59e7f7796c075b7fd03145e5f9c69625403b..6a5a3166b1823e751dfe19a28bf54c147dd798b3 100755 (executable)
@@ -14,6 +14,7 @@ test_expect_success setup '
                echo expect
                echo ignored
        ) >.gitignore &&
+       git --literal-pathspecs add --all &&
        >will-remove &&
        git add --all &&
        test_tick &&