Skip to content

Commit b5227d8

Browse files
peffgitster
authored andcommitted
ls-files: excludes should not impact tracked files
In all parts of git, .gitignore and other exclude files impact only how we treat untracked files; they should have no effect on files listed in the index. This behavior was originally implemented very early on in 9ff768e, but only for --exclude-from. Later, commit 63d285c accidentally caused us to trigger the behavior for --exclude-per-directory. This patch totally ignores excludes for files found in the index. This means we are reversing the original intent of 9ff768e, while at the same time fixing the accidental behavior of 63d285c. This is a good thing, though, as the way that 9ff768e behaved does not really make sense with the way exclusions are used in modern git. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f01f109 commit b5227d8

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

builtin-ls-files.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ 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 (excluded(dir, ce->name, &dtype) !=
180-
!!(dir->flags & DIR_SHOW_IGNORED))
181-
continue;
182178
if (show_unmerged && !ce_stage(ce))
183179
continue;
184180
if (ce->ce_flags & CE_UPDATE)
@@ -191,10 +187,6 @@ static void show_files(struct dir_struct *dir, const char *prefix)
191187
struct cache_entry *ce = active_cache[i];
192188
struct stat st;
193189
int err;
194-
int dtype = ce_to_dtype(ce);
195-
if (excluded(dir, ce->name, &dtype) !=
196-
!!(dir->flags & DIR_SHOW_IGNORED))
197-
continue;
198190
if (ce->ce_flags & CE_UPDATE)
199191
continue;
200192
err = lstat(ce->name, &st);

t/t3003-ls-files-exclude.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
test_description='ls-files --exclude does not affect index files'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'create repo with file' '
7+
echo content >file &&
8+
git add file &&
9+
git commit -m file &&
10+
echo modification >file
11+
'
12+
13+
check_output() {
14+
test_expect_success "ls-files output contains file ($1)" "
15+
echo '$2' >expect &&
16+
git ls-files --exclude-standard --$1 >output &&
17+
test_cmp expect output
18+
"
19+
}
20+
21+
check_all_output() {
22+
check_output 'cached' 'file'
23+
check_output 'modified' 'file'
24+
}
25+
26+
check_all_output
27+
test_expect_success 'add file to gitignore' '
28+
echo file >.gitignore
29+
'
30+
check_all_output
31+
32+
test_done

0 commit comments

Comments
 (0)