git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] Fix handling of matching nonbare repo vs. matching something under nonbare repo
@ 2020-08-12  7:12 Elijah Newren via GitGitGadget
  2020-08-12  7:12 ` [PATCH 1/2] t3000: fix some test description typos Elijah Newren via GitGitGadget
  2020-08-12  7:12 ` [PATCH 2/2] dir: avoid prematurely marking nonbare repositories as matches Elijah Newren via GitGitGadget
  0 siblings, 2 replies; 3+ messages in thread
From: Elijah Newren via GitGitGadget @ 2020-08-12  7:12 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren

This fixes the issue reported at 
https://lore.kernel.org/git/CADjceoQxoL932W4mkfhG6VOgrQBhs9k6tXkWSkraKVPmUP+uCw@mail.gmail.com/
, a regression in git-2.27.0 (that wasn't reported until after 2.28.0). It
involves running ls-files --others with globs when nonbare repositories are
present.

Thanks to christian w for reporting, and Kyle Meyer for finding a way to
simplify the testcase and bisecting. Very helpful.

Elijah Newren (2):
  t3000: fix some test description typos
  dir: avoid prematurely marking nonbare repositories as matches

 dir.c                      |  9 ++++++---
 t/t3000-ls-files-others.sh | 24 ++++++++++++++++++++----
 2 files changed, 26 insertions(+), 7 deletions(-)


base-commit: 47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-829%2Fnewren%2Fls-files-wildmatch-nonbare-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-829/newren/ls-files-wildmatch-nonbare-v1
Pull-Request: https://github.com/git/git/pull/829
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] t3000: fix some test description typos
  2020-08-12  7:12 [PATCH 0/2] Fix handling of matching nonbare repo vs. matching something under nonbare repo Elijah Newren via GitGitGadget
@ 2020-08-12  7:12 ` Elijah Newren via GitGitGadget
  2020-08-12  7:12 ` [PATCH 2/2] dir: avoid prematurely marking nonbare repositories as matches Elijah Newren via GitGitGadget
  1 sibling, 0 replies; 3+ messages in thread
From: Elijah Newren via GitGitGadget @ 2020-08-12  7:12 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

There is no such flag as --o; it is either --others or -o.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t3000-ls-files-others.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/t3000-ls-files-others.sh b/t/t3000-ls-files-others.sh
index ffdfb16f58..1b9327b780 100755
--- a/t/t3000-ls-files-others.sh
+++ b/t/t3000-ls-files-others.sh
@@ -152,7 +152,7 @@ test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' '
 	)
 '
 
-test_expect_success 'ls-files --o --directory with glob filetype match' '
+test_expect_success 'ls-files -o --directory with glob filetype match' '
 	(
 		cd nested &&
 
@@ -168,7 +168,7 @@ test_expect_success 'ls-files --o --directory with glob filetype match' '
 	)
 '
 
-test_expect_success 'ls-files --o --directory with mix of tracked states' '
+test_expect_success 'ls-files -o --directory with mix of tracked states' '
 	(
 		cd nested &&
 
@@ -184,7 +184,7 @@ test_expect_success 'ls-files --o --directory with mix of tracked states' '
 	)
 '
 
-test_expect_success 'ls-files --o --directory with glob filetype match only' '
+test_expect_success 'ls-files -o --directory with glob filetype match only' '
 	(
 		cd nested &&
 
@@ -198,7 +198,7 @@ test_expect_success 'ls-files --o --directory with glob filetype match only' '
 	)
 '
 
-test_expect_success 'ls-files --o --directory to get immediate paths under one dir only' '
+test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' '
 	(
 		cd nested &&
 
-- 
gitgitgadget


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] dir: avoid prematurely marking nonbare repositories as matches
  2020-08-12  7:12 [PATCH 0/2] Fix handling of matching nonbare repo vs. matching something under nonbare repo Elijah Newren via GitGitGadget
  2020-08-12  7:12 ` [PATCH 1/2] t3000: fix some test description typos Elijah Newren via GitGitGadget
@ 2020-08-12  7:12 ` Elijah Newren via GitGitGadget
  1 sibling, 0 replies; 3+ messages in thread
From: Elijah Newren via GitGitGadget @ 2020-08-12  7:12 UTC (permalink / raw)
  To: git; +Cc: Elijah Newren, Elijah Newren

From: Elijah Newren <newren@gmail.com>

Nonbare repositories are special directories.  Unlike normal directories
that we might recurse into to list the files they contain, nonbare
repositories must themselves match and then we always report only on the
nonbare repository directory itself and not on any of its contents.

Separately, when traversing directories to try to find untracked or
excluded files, we often think in terms of paths either matching the
specified pathspec, or not matching them.  However, there is a special
value that do_match_pathspec() uses named
MATCHED_RECURSIVELY_LEADING_PATHSPEC which means "this directory does
not match any pathspec BUT it is possible a file or directory underneath
it does."  That special value prevents us from prematurely thinking that
some directory and everything under it is irrelevant, but also allows us
to differentiate from "this is a match".

The combination of these two special cases was previously uncovered.
Add a test to the testsuite to cover it, and make sure that we return a
nonbare repository as a non-match if the best match it got was
MATCHED_RECURSIVELY_LEADING_PATHSPEC.

Reported-by: christian w <usebees@gmail.com>
Simplified-testcase-and-bisection-by: Kyle Meyer <kyle@kyleam.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 dir.c                      |  9 ++++++---
 t/t3000-ls-files-others.sh | 16 ++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/dir.c b/dir.c
index 1045cc9c6f..b5082ca05f 100644
--- a/dir.c
+++ b/dir.c
@@ -1792,9 +1792,12 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
 		nested_repo = is_nonbare_repository_dir(&sb);
 		strbuf_release(&sb);
 	}
-	if (nested_repo)
-		return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
-			(excluded ? path_excluded : path_untracked));
+	if (nested_repo) {
+		if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
+		    (matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC))
+			return path_none;
+		return excluded ? path_excluded : path_untracked;
+	}
 
 	if (!(dir->flags & DIR_SHOW_OTHER_DIRECTORIES)) {
 		if (excluded &&
diff --git a/t/t3000-ls-files-others.sh b/t/t3000-ls-files-others.sh
index 1b9327b780..740ce56eab 100755
--- a/t/t3000-ls-files-others.sh
+++ b/t/t3000-ls-files-others.sh
@@ -212,4 +212,20 @@ test_expect_success 'ls-files -o --directory to get immediate paths under one di
 	)
 '
 
+test_expect_success 'ls-files -o avoids listing untracked non-matching gitdir' '
+	test_when_finished "rm -rf nested/untracked/deep/empty" &&
+	(
+		cd nested &&
+
+		git init untracked/deep/empty &&
+		git ls-files --others "untracked/*.c" >actual &&
+
+		cat <<-EOF >expect &&
+		untracked/deep/foo.c
+		EOF
+
+		test_cmp expect actual
+	)
+'
+
 test_done
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-12  7:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12  7:12 [PATCH 0/2] Fix handling of matching nonbare repo vs. matching something under nonbare repo Elijah Newren via GitGitGadget
2020-08-12  7:12 ` [PATCH 1/2] t3000: fix some test description typos Elijah Newren via GitGitGadget
2020-08-12  7:12 ` [PATCH 2/2] dir: avoid prematurely marking nonbare repositories as matches Elijah Newren via GitGitGadget

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).