Skip to content

Commit 11f433f

Browse files
committed
Merge branch 'en/dir-nonbare-embedded'
"ls-files -o" mishandled the top-level directory of another git working tree that hangs in the current git working tree. * en/dir-nonbare-embedded: dir: avoid prematurely marking nonbare repositories as matches t3000: fix some test description typos
2 parents 9e8c754 + ab282aa commit 11f433f

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

dir.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,9 +1792,12 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
17921792
nested_repo = is_nonbare_repository_dir(&sb);
17931793
strbuf_release(&sb);
17941794
}
1795-
if (nested_repo)
1796-
return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
1797-
(excluded ? path_excluded : path_untracked));
1795+
if (nested_repo) {
1796+
if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
1797+
(matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC))
1798+
return path_none;
1799+
return excluded ? path_excluded : path_untracked;
1800+
}
17981801

17991802
if (!(dir->flags & DIR_SHOW_OTHER_DIRECTORIES)) {
18001803
if (excluded &&

t/t3000-ls-files-others.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' '
152152
)
153153
'
154154

155-
test_expect_success 'ls-files --o --directory with glob filetype match' '
155+
test_expect_success 'ls-files -o --directory with glob filetype match' '
156156
(
157157
cd nested &&
158158
@@ -168,7 +168,7 @@ test_expect_success 'ls-files --o --directory with glob filetype match' '
168168
)
169169
'
170170

171-
test_expect_success 'ls-files --o --directory with mix of tracked states' '
171+
test_expect_success 'ls-files -o --directory with mix of tracked states' '
172172
(
173173
cd nested &&
174174
@@ -184,7 +184,7 @@ test_expect_success 'ls-files --o --directory with mix of tracked states' '
184184
)
185185
'
186186

187-
test_expect_success 'ls-files --o --directory with glob filetype match only' '
187+
test_expect_success 'ls-files -o --directory with glob filetype match only' '
188188
(
189189
cd nested &&
190190
@@ -198,7 +198,7 @@ test_expect_success 'ls-files --o --directory with glob filetype match only' '
198198
)
199199
'
200200

201-
test_expect_success 'ls-files --o --directory to get immediate paths under one dir only' '
201+
test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' '
202202
(
203203
cd nested &&
204204
@@ -212,4 +212,20 @@ test_expect_success 'ls-files --o --directory to get immediate paths under one d
212212
)
213213
'
214214

215+
test_expect_success 'ls-files -o avoids listing untracked non-matching gitdir' '
216+
test_when_finished "rm -rf nested/untracked/deep/empty" &&
217+
(
218+
cd nested &&
219+
220+
git init untracked/deep/empty &&
221+
git ls-files --others "untracked/*.c" >actual &&
222+
223+
cat <<-EOF >expect &&
224+
untracked/deep/foo.c
225+
EOF
226+
227+
test_cmp expect actual
228+
)
229+
'
230+
215231
test_done

0 commit comments

Comments
 (0)