Skip to content

Commit 500348a

Browse files
peffgitster
authored andcommitted
ls-files: unbreak "ls-files -i"
Commit b5227d8 changed the behavior of "ls-files" with respect to includes, but accidentally broke the "-i" option The original behavior was: 1. if no "-i" is given, cull all results according to --exclude* 2. if "-i" is given, show the inverse of (1) The broken behavior was: 1. if no "-i" is given: a. for "-o", cull results according to --exclude* b. for index files, always show all 2. if "-i" is given: a. for "-o", shows the inverse of (1a) b. for index files, always show all The fixed behavior keeps the new (1b) behavior introduced by b5227d8, but fixes the (2b) behavior to show only ignored files, not all files. This patch also tweaks the documentation. The original text was somewhat obscure in the first place, but it is also now inaccurate (the relationship between (1b) and (2b) is not quite a "reverse"). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b5227d8 commit 500348a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Documentation/git-ls-files.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ OPTIONS
4848

4949
-i::
5050
--ignored::
51-
Show ignored files in the output.
52-
Note that this also reverses any exclude list present.
51+
Show only ignored files in the output. When showing files in the
52+
index, print only those matched by an exclude pattern. When
53+
showing "other" files, show only those matched by an exclude
54+
pattern.
5355

5456
-s::
5557
--stage::

builtin-ls-files.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ static void show_files(struct dir_struct *dir, const char *prefix)
175175
if (show_cached | show_stage) {
176176
for (i = 0; i < active_nr; i++) {
177177
struct cache_entry *ce = active_cache[i];
178+
int dtype = ce_to_dtype(ce);
179+
if (dir->flags & DIR_SHOW_IGNORED &&
180+
!excluded(dir, ce->name, &dtype))
181+
continue;
178182
if (show_unmerged && !ce_stage(ce))
179183
continue;
180184
if (ce->ce_flags & CE_UPDATE)
@@ -187,6 +191,10 @@ static void show_files(struct dir_struct *dir, const char *prefix)
187191
struct cache_entry *ce = active_cache[i];
188192
struct stat st;
189193
int err;
194+
int dtype = ce_to_dtype(ce);
195+
if (dir->flags & DIR_SHOW_IGNORED &&
196+
!excluded(dir, ce->name, &dtype))
197+
continue;
190198
if (ce->ce_flags & CE_UPDATE)
191199
continue;
192200
err = lstat(ce->name, &st);

t/t3003-ls-files-exclude.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ 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' '
33+
echo content >other-file &&
34+
git add other-file &&
35+
echo file >expect &&
36+
git ls-files -i --exclude-standard >output &&
37+
test_cmp expect output
38+
'
39+
3240
test_done

0 commit comments

Comments
 (0)