summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-05-12 17:28:16 +0000
committerJunio C Hamano <gitster@pobox.com>2021-05-13 08:45:03 +0900
commitb338e9f668737e08201c990450b8c3d744f63162 (patch)
treec666900caf1bfd1276b41b09351a4e3272d75715
parent7fe1ffdafa56b8453a47a40b866d029f24a56d76 (diff)
downloadgit-b338e9f668737e08201c990450b8c3d744f63162.tar.gz
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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/ls-files.c3
-rwxr-xr-xt/t1306-xdg-files.sh2
-rwxr-xr-xt/t3003-ls-files-exclude.sh4
3 files changed, 6 insertions, 3 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index f6f9e483b2..cd01404417 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -675,6 +675,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
if (pathspec.nr && error_unmatch)
ps_matched = xcalloc(pathspec.nr, 1);
+ if ((dir.flags & DIR_SHOW_IGNORED) && !show_others && !show_cached)
+ die("ls-files -i must be used with either -o or -c");
+
if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given)
die("ls-files --ignored needs some exclude pattern");
diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh
index dd87b43be1..40d3c42618 100755
--- a/t/t1306-xdg-files.sh
+++ b/t/t1306-xdg-files.sh
@@ -116,7 +116,7 @@ test_expect_success 'Exclusion in a non-XDG global ignore file' '
test_expect_success 'Checking XDG ignore file when HOME is unset' '
(sane_unset HOME &&
git config --unset core.excludesfile &&
- git ls-files --exclude-standard --ignored >actual) &&
+ git ls-files --exclude-standard --ignored --others >actual) &&
test_must_be_empty actual
'
diff --git a/t/t3003-ls-files-exclude.sh b/t/t3003-ls-files-exclude.sh
index d5ec333131..c41c4f046a 100755
--- a/t/t3003-ls-files-exclude.sh
+++ b/t/t3003-ls-files-exclude.sh
@@ -29,11 +29,11 @@ test_expect_success 'add file to gitignore' '
'
check_all_output
-test_expect_success 'ls-files -i lists only tracked-but-ignored files' '
+test_expect_success 'ls-files -i -c lists only tracked-but-ignored files' '
echo content >other-file &&
git add other-file &&
echo file >expect &&
- git ls-files -i --exclude-standard >output &&
+ git ls-files -i -c --exclude-standard >output &&
test_cmp expect output
'