@matheusbsbs / matheus-bagliano / commits / 500348aa68
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 30, 2009 at 15:05 UTC 500348aa6859e436a890f5f5a7e0eeea8ef6c1de
3 files changed +20 -2
Documentation/git-ls-files.txt
+4 -2
@@ -48,8 +48,10 @@ OPTIONS
48
49 -i::
50 --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.
55
56 -s::
57 --stage::
builtin-ls-files.c
+8
@@ -175,6 +175,10 @@ static void show_files(struct dir_struct *dir, const char *prefix)
175 if (show_cached | show_stage) {
176 for (i = 0; i < active_nr; i++) {
177 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;
182 if (show_unmerged && !ce_stage(ce))
183 continue;
184 if (ce->ce_flags & CE_UPDATE)
@@ -187,6 +191,10 @@ static void show_files(struct dir_struct *dir, const char *prefix)
191 struct cache_entry *ce = active_cache[i];
192 struct stat st;
193 int err;
194 + int dtype = ce_to_dtype(ce);
195 + if (dir->flags & DIR_SHOW_IGNORED &&
196 + !excluded(dir, ce->name, &dtype))
197 + continue;
198 if (ce->ce_flags & CE_UPDATE)
199 continue;
200 err = lstat(ce->name, &st);
t/t3003-ls-files-exclude.sh
+8
@@ -29,4 +29,12 @@ test_expect_success 'add file to gitignore' '
29 '
30 check_all_output
31
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 +
40 test_done