{"thread":{"id":"54024","subject":"[PATCH 0/2] Fix handling of matching nonbare repo vs. matching something under nonbare repo","startedAt":"2020-08-12T07:12:41Z","lastAt":"2020-08-12T07:12:43Z","messageCount":3,"participants":["Elijah Newren via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"403432","messageId":"pull.829.git.git.1597216356.gitgitgadget@gmail.com","threadId":"54024","inReplyTo":null,"subject":"[PATCH 0/2] Fix handling of matching nonbare repo vs. matching something under nonbare repo","fromName":"Elijah Newren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-08-12T07:12:34Z","receivedAt":"2020-08-12T07:12:41Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"This fixes the issue reported at \nhttps://lore.kernel.org/git/CADjceoQxoL932W4mkfhG6VOgrQBhs9k6tXkWSkraKVPmUP+uCw@mail.gmail.com/\n, a regression in git-2.27.0 (that wasn't reported until after 2.28.0). It\ninvolves running ls-files --others with globs when nonbare repositories are\npresent.\n\nThanks to christian w for reporting, and Kyle Meyer for finding a way to\nsimplify the testcase and bisecting. Very helpful.\n\nElijah Newren (2):\n  t3000: fix some test description typos\n  dir: avoid prematurely marking nonbare repositories as matches\n\n dir.c                      |  9 ++++++---\n t/t3000-ls-files-others.sh | 24 ++++++++++++++++++++----\n 2 files changed, 26 insertions(+), 7 deletions(-)\n\n\nbase-commit: 47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-829%2Fnewren%2Fls-files-wildmatch-nonbare-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-829/newren/ls-files-wildmatch-nonbare-v1\nPull-Request: https://github.com/git/git/pull/829\n-- \ngitgitgadget\n"},{"id":"403433","messageId":"11a286b071ca8a6b96f4fba6658e9bafb9314be4.1597216356.git.gitgitgadget@gmail.com","threadId":"54024","inReplyTo":"pull.829.git.git.1597216356.gitgitgadget@gmail.com","subject":"[PATCH 2/2] dir: avoid prematurely marking nonbare repositories as matches","fromName":"Elijah Newren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-08-12T07:12:36Z","receivedAt":"2020-08-12T07:12:42Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"From: Elijah Newren <newren@gmail.com>\n\nNonbare repositories are special directories.  Unlike normal directories\nthat we might recurse into to list the files they contain, nonbare\nrepositories must themselves match and then we always report only on the\nnonbare repository directory itself and not on any of its contents.\n\nSeparately, when traversing directories to try to find untracked or\nexcluded files, we often think in terms of paths either matching the\nspecified pathspec, or not matching them.  However, there is a special\nvalue that do_match_pathspec() uses named\nMATCHED_RECURSIVELY_LEADING_PATHSPEC which means \"this directory does\nnot match any pathspec BUT it is possible a file or directory underneath\nit does.\"  That special value prevents us from prematurely thinking that\nsome directory and everything under it is irrelevant, but also allows us\nto differentiate from \"this is a match\".\n\nThe combination of these two special cases was previously uncovered.\nAdd a test to the testsuite to cover it, and make sure that we return a\nnonbare repository as a non-match if the best match it got was\nMATCHED_RECURSIVELY_LEADING_PATHSPEC.\n\nReported-by: christian w <usebees@gmail.com>\nSimplified-testcase-and-bisection-by: Kyle Meyer <kyle@kyleam.com>\nSigned-off-by: Elijah Newren <newren@gmail.com>\n---\n dir.c                      |  9 ++++++---\n t/t3000-ls-files-others.sh | 16 ++++++++++++++++\n 2 files changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex 1045cc9c6f..b5082ca05f 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1792,9 +1792,12 @@ static enum path_treatment treat_directory(struct dir_struct *dir,\n \t\tnested_repo = is_nonbare_repository_dir(&sb);\n \t\tstrbuf_release(&sb);\n \t}\n-\tif (nested_repo)\n-\t\treturn ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :\n-\t\t\t(excluded ? path_excluded : path_untracked));\n+\tif (nested_repo) {\n+\t\tif ((dir->flags & DIR_SKIP_NESTED_GIT) ||\n+\t\t    (matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC))\n+\t\t\treturn path_none;\n+\t\treturn excluded ? path_excluded : path_untracked;\n+\t}\n \n \tif (!(dir->flags & DIR_SHOW_OTHER_DIRECTORIES)) {\n \t\tif (excluded &&\ndiff --git a/t/t3000-ls-files-others.sh b/t/t3000-ls-files-others.sh\nindex 1b9327b780..740ce56eab 100755\n--- a/t/t3000-ls-files-others.sh\n+++ b/t/t3000-ls-files-others.sh\n@@ -212,4 +212,20 @@ test_expect_success 'ls-files -o --directory to get immediate paths under one di\n \t)\n '\n \n+test_expect_success 'ls-files -o avoids listing untracked non-matching gitdir' '\n+\ttest_when_finished \"rm -rf nested/untracked/deep/empty\" &&\n+\t(\n+\t\tcd nested &&\n+\n+\t\tgit init untracked/deep/empty &&\n+\t\tgit ls-files --others \"untracked/*.c\" >actual &&\n+\n+\t\tcat <<-EOF >expect &&\n+\t\tuntracked/deep/foo.c\n+\t\tEOF\n+\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n test_done\n-- \ngitgitgadget\n"},{"id":"403434","messageId":"8a2a0b6c9adea54bd5d10c37bbc6965eb5cb120b.1597216356.git.gitgitgadget@gmail.com","threadId":"54024","inReplyTo":"pull.829.git.git.1597216356.gitgitgadget@gmail.com","subject":"[PATCH 1/2] t3000: fix some test description typos","fromName":"Elijah Newren via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-08-12T07:12:35Z","receivedAt":"2020-08-12T07:12:43Z","isPatch":true,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"From: Elijah Newren <newren@gmail.com>\n\nThere is no such flag as --o; it is either --others or -o.\n\nSigned-off-by: Elijah Newren <newren@gmail.com>\n---\n t/t3000-ls-files-others.sh | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t3000-ls-files-others.sh b/t/t3000-ls-files-others.sh\nindex ffdfb16f58..1b9327b780 100755\n--- a/t/t3000-ls-files-others.sh\n+++ b/t/t3000-ls-files-others.sh\n@@ -152,7 +152,7 @@ test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' '\n \t)\n '\n \n-test_expect_success 'ls-files --o --directory with glob filetype match' '\n+test_expect_success 'ls-files -o --directory with glob filetype match' '\n \t(\n \t\tcd nested &&\n \n@@ -168,7 +168,7 @@ test_expect_success 'ls-files --o --directory with glob filetype match' '\n \t)\n '\n \n-test_expect_success 'ls-files --o --directory with mix of tracked states' '\n+test_expect_success 'ls-files -o --directory with mix of tracked states' '\n \t(\n \t\tcd nested &&\n \n@@ -184,7 +184,7 @@ test_expect_success 'ls-files --o --directory with mix of tracked states' '\n \t)\n '\n \n-test_expect_success 'ls-files --o --directory with glob filetype match only' '\n+test_expect_success 'ls-files -o --directory with glob filetype match only' '\n \t(\n \t\tcd nested &&\n \n@@ -198,7 +198,7 @@ test_expect_success 'ls-files --o --directory with glob filetype match only' '\n \t)\n '\n \n-test_expect_success 'ls-files --o --directory to get immediate paths under one dir only' '\n+test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' '\n \t(\n \t\tcd nested &&\n \n-- \ngitgitgadget\n\n"}]}