Skip to content

Commit 07d7bed

Browse files
peffgitster
authored andcommitted
add: don't complain when adding empty project root
We try to warn the user if one of their pathspecs caused no matches, as it may have been a typo. However, we disable the warning if the pathspec points to an existing file, since that means it is not a typo but simply an empty directory. Unfortunately, the file_exists() test was broken for one special case: the pathspec of the project root is just "". This patch detects this special case and acts as if the file exists (which it must, since it is the project root). The user-visible effect is that this: $ mkdir repo && cd repo && git init && git add . used to complain like: fatal: pathspec '' did not match any files but now is a silent no-op. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec00d6e commit 07d7bed

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin-add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
6161
fill_pathspec_matches(pathspec, seen, specs);
6262

6363
for (i = 0; i < specs; i++) {
64-
if (!seen[i] && !file_exists(pathspec[i]))
64+
if (!seen[i] && pathspec[i][0] && !file_exists(pathspec[i]))
6565
die("pathspec '%s' did not match any files",
6666
pathspec[i]);
6767
}

0 commit comments

Comments
 (0)