Skip to content

Commit 29abb33

Browse files
committed
add: simplify -u/-A without pathspec
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 5a76aff (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 <[email protected]>
1 parent 282616c commit 29abb33

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

builtin/add.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
336336
if (!show_only && ignore_missing)
337337
die(_("Option --ignore-missing can only be used together with --dry-run"));
338338

339-
if ((0 < addremove_explicit || take_worktree_changes) && !argc) {
340-
static const char *whole[2] = { ":/", NULL };
341-
argc = 1;
342-
argv = whole;
343-
}
344-
345339
add_new_files = !take_worktree_changes && !refresh_only;
346-
require_pathspec = !take_worktree_changes;
340+
require_pathspec = !(take_worktree_changes || (0 < addremove_explicit));
347341

348342
newfd = hold_locked_index(&lock_file, 1);
349343

t/t2200-add-update.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ test_expect_success 'non-qualified update in subdir updates from the root' '
8484
(
8585
cd dir1 &&
8686
echo even more >>sub2 &&
87+
git --literal-pathspecs add -u &&
88+
echo even more >>sub2 &&
8789
git add -u
8890
) &&
8991
: >expect &&

t/t2202-add-addremove.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test_expect_success setup '
1414
echo expect
1515
echo ignored
1616
) >.gitignore &&
17+
git --literal-pathspecs add --all &&
1718
>will-remove &&
1819
git add --all &&
1920
test_tick &&

0 commit comments

Comments
 (0)