@matheusbsbs / matheus-bagliano / commits / b5227d80ae
Fork 0

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

Jeff King committed Oct 12, 2009 at 01:11 UTC b5227d80aee5173bfda6aa43a890d03110b0df26
2 files changed +32 -8
builtin-ls-files.c
-8
@@ -175,10 +175,6 @@ 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 (excluded(dir, ce->name, &dtype) !=
180 - !!(dir->flags & DIR_SHOW_IGNORED))
181 - continue;
178 if (show_unmerged && !ce_stage(ce))
179 continue;
180 if (ce->ce_flags & CE_UPDATE)
@@ -191,10 +187,6 @@ static void show_files(struct dir_struct *dir, const char *prefix)
187 struct cache_entry *ce = active_cache[i];
188 struct stat st;
189 int err;
194 - int dtype = ce_to_dtype(ce);
195 - if (excluded(dir, ce->name, &dtype) !=
196 - !!(dir->flags & DIR_SHOW_IGNORED))
197 - continue;
190 if (ce->ce_flags & CE_UPDATE)
191 continue;
192 err = lstat(ce->name, &st);
t/t3003-ls-files-exclude.sh new
+32
@@ -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