Skip to content

Commit b338e9f

Browse files
newrengitster
authored andcommitted
ls-files: error out on -i unless -o or -c are specified
ls-files --ignored can be used together with either --others or --cached. After being perplexed for a bit and digging in to the code, I assumed that ls-files -i was just broken and not printing anything and I had a nice patch ready to submit when I finally realized that -i can be used with --cached to find tracked ignores. While that was a mistake on my part, and a careful reading of the documentation could have made this more clear, I suspect this is an error others are likely to make as well. In fact, of two uses in our testsuite, I believe one of the two did make this error. In t1306.13, there are NO tracked files, and all the excludes built up and used in that test and in previous tests thus have to be about untracked files. However, since they were looking for an empty result, the mistake went unnoticed as their erroneous command also just happened to give an empty answer. -i will most the time be used with -o, which would suggest we could just make -i imply -o in the absence of either a -o or -c, but that would be a backward incompatible break. Instead, let's just flag -i without either a -o or -c as an error, and update the two relevant testcases to specify their intent. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7fe1ffd commit b338e9f

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

builtin/ls-files.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
675675
if (pathspec.nr && error_unmatch)
676676
ps_matched = xcalloc(pathspec.nr, 1);
677677

678+
if ((dir.flags & DIR_SHOW_IGNORED) && !show_others && !show_cached)
679+
die("ls-files -i must be used with either -o or -c");
680+
678681
if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given)
679682
die("ls-files --ignored needs some exclude pattern");
680683

t/t1306-xdg-files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ test_expect_success 'Exclusion in a non-XDG global ignore file' '
116116
test_expect_success 'Checking XDG ignore file when HOME is unset' '
117117
(sane_unset HOME &&
118118
git config --unset core.excludesfile &&
119-
git ls-files --exclude-standard --ignored >actual) &&
119+
git ls-files --exclude-standard --ignored --others >actual) &&
120120
test_must_be_empty actual
121121
'
122122

t/t3003-ls-files-exclude.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ test_expect_success 'add file to gitignore' '
2929
'
3030
check_all_output
3131

32-
test_expect_success 'ls-files -i lists only tracked-but-ignored files' '
32+
test_expect_success 'ls-files -i -c lists only tracked-but-ignored files' '
3333
echo content >other-file &&
3434
git add other-file &&
3535
echo file >expect &&
36-
git ls-files -i --exclude-standard >output &&
36+
git ls-files -i -c --exclude-standard >output &&
3737
test_cmp expect output
3838
'
3939

0 commit comments

Comments
 (0)