Skip to content

Commit a2b1336

Browse files
newrengitster
authored andcommitted
Revert "dir.c: make 'git-status --ignored' work within leading directories"
Commit be8a84c ("dir.c: make 'git-status --ignored' work within leading directories", 2013-04-15) noted that git status --ignored <SOMEPATH> would not list ignored files and directories within <SOMEPATH> if <SOMEPATH> was untracked, and modified the behavior to make it show them. However, it did so via a hack that broke consistency; it would show paths under <SOMEPATH> differently than a simple git status --ignored | grep <SOMEPATH> would show them. A correct fix is slightly more involved, and complicated slightly by this hack, so we revert this commit (but keep corrected versions of the testcases) and will later fix the original bug with a subsequent patch. Some history may be helpful: A very, very similar case to the commit we are reverting was raised in commit 48ffef9 ("ls-files: fix overeager pathspec optimization", 2010-01-08); but it actually went in somewhat the opposite direction. In that commit, it mentioned how git ls-files -o --exclude-standard t/ used to show untracked files under t/ even when t/ was ignored, and then changed the behavior to stop showing untracked files under an ignored directory. More importantly, this commit considered keeping this behavior but noted that it would be inconsistent with the behavior when multiple pathspecs were specified and thus rejected it. The reason for this whole inconsistency when one pathspec is specified versus zero or two is because common prefixes of pathspecs are sent through a different set of checks (in treat_leading_path()) than normal file/directory traversal (those go through read_directory_recursive() and treat_path()). As such, for consistency, one needs to check that both codepaths produce the same result. Revert commit be8a84c, except instead of removing the testcase it added, modify it to check for correct and consistent behavior. A subsequent patch in this series will fix the testcase. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 452efd1 commit a2b1336

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

dir.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,14 +2083,12 @@ static int treat_leading_path(struct dir_struct *dir,
20832083
struct strbuf sb = STRBUF_INIT;
20842084
int baselen, rc = 0;
20852085
const char *cp;
2086-
int old_flags = dir->flags;
20872086

20882087
while (len && path[len - 1] == '/')
20892088
len--;
20902089
if (!len)
20912090
return 1;
20922091
baselen = 0;
2093-
dir->flags &= ~DIR_SHOW_OTHER_DIRECTORIES;
20942092
while (1) {
20952093
cp = path + baselen + !!baselen;
20962094
cp = memchr(cp, '/', path + len - cp);
@@ -2113,7 +2111,6 @@ static int treat_leading_path(struct dir_struct *dir,
21132111
}
21142112
}
21152113
strbuf_release(&sb);
2116-
dir->flags = old_flags;
21172114
return rc;
21182115
}
21192116

t/t7061-wtstatus-ignore.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ test_expect_success 'status untracked directory with --ignored -u' '
4343
test_cmp expected actual
4444
'
4545
cat >expected <<\EOF
46-
?? untracked/uncommitted
46+
?? untracked/
4747
!! untracked/ignored
4848
EOF
4949

50-
test_expect_success 'status prefixed untracked directory with --ignored' '
50+
test_expect_failure 'status of untracked directory with --ignored works with or without prefix' '
51+
git status --porcelain --ignored >tmp &&
52+
grep untracked/ tmp >actual &&
53+
rm tmp &&
54+
test_cmp expected actual &&
55+
5156
git status --porcelain --ignored untracked/ >actual &&
5257
test_cmp expected actual
5358
'

0 commit comments

Comments
 (0)