Skip to content

Commit be8a84c

Browse files
kbleesgitster
authored andcommitted
dir.c: make 'git-status --ignored' work within leading directories
'git-status --ignored path/' doesn't list ignored files and directories within 'path' if some component of 'path' is classified as untracked. Disable the DIR_SHOW_OTHER_DIRECTORIES flag while traversing leading directories. This prevents treat_leading_path() with DIR_SHOW_IGNORED flag from aborting at the top level untracked directory. As a side effect, this also eliminates a recursive directory scan per leading directory level, as treat_directory() can no longer call read_directory_recursive() when called from treat_leading_path(). Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c94ab01 commit be8a84c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

dir.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,12 +1447,14 @@ static int treat_leading_path(struct dir_struct *dir,
14471447
struct strbuf sb = STRBUF_INIT;
14481448
int baselen, rc = 0;
14491449
const char *cp;
1450+
int old_flags = dir->flags;
14501451

14511452
while (len && path[len - 1] == '/')
14521453
len--;
14531454
if (!len)
14541455
return 1;
14551456
baselen = 0;
1457+
dir->flags &= ~DIR_SHOW_OTHER_DIRECTORIES;
14561458
while (1) {
14571459
cp = path + baselen + !!baselen;
14581460
cp = memchr(cp, '/', path + len - cp);
@@ -1475,6 +1477,7 @@ static int treat_leading_path(struct dir_struct *dir,
14751477
}
14761478
}
14771479
strbuf_release(&sb);
1480+
dir->flags = old_flags;
14781481
return rc;
14791482
}
14801483

t/t7061-wtstatus-ignore.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ test_expect_success 'status untracked directory with --ignored -u' '
3232
git status --porcelain --ignored -u >actual &&
3333
test_cmp expected actual
3434
'
35+
cat >expected <<\EOF
36+
?? untracked/uncommitted
37+
!! untracked/ignored
38+
EOF
39+
40+
test_expect_success 'status prefixed untracked directory with --ignored' '
41+
git status --porcelain --ignored untracked/ >actual &&
42+
test_cmp expected actual
43+
'
44+
45+
cat >expected <<\EOF
46+
?? untracked/uncommitted
47+
!! untracked/ignored
48+
EOF
49+
50+
test_expect_success 'status prefixed untracked sub-directory with --ignored -u' '
51+
git status --porcelain --ignored -u untracked/ >actual &&
52+
test_cmp expected actual
53+
'
3554

3655
cat >expected <<\EOF
3756
?? .gitignore

0 commit comments

Comments
 (0)