]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t7814-grep-recurse-submodules.sh
Sync with 2.33.5
[thirdparty/git.git] / t / t7814-grep-recurse-submodules.sh
index f465c0d1403c974165b418d8a1836f90d0ebe53c..a10b20c87f1fbe85e706165eb8eeedf325c63b42 100755 (executable)
@@ -8,6 +8,9 @@ submodules.
 
 . ./test-lib.sh
 
+GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
+export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
+
 test_expect_success 'setup directory structure and submodule' '
        echo "(1|2)d(3|4)" >a &&
        mkdir b &&
@@ -442,4 +445,107 @@ test_expect_success 'grep --recurse-submodules with --cached ignores worktree mo
        test_must_fail git grep --recurse-submodules --cached "A modified line in submodule" >actual 2>&1 &&
        test_must_be_empty actual
 '
+
+test_expect_failure 'grep --textconv: superproject .gitattributes does not affect submodules' '
+       reset_and_clean &&
+       test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
+       echo "a diff=d2x" >.gitattributes &&
+
+       cat >expect <<-\EOF &&
+       a:(1|2)x(3|4)
+       EOF
+       git grep --textconv --recurse-submodules x >actual &&
+       test_cmp expect actual
+'
+
+test_expect_failure 'grep --textconv: superproject .gitattributes (from index) does not affect submodules' '
+       reset_and_clean &&
+       test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
+       echo "a diff=d2x" >.gitattributes &&
+       git add .gitattributes &&
+       rm .gitattributes &&
+
+       cat >expect <<-\EOF &&
+       a:(1|2)x(3|4)
+       EOF
+       git grep --textconv --recurse-submodules x >actual &&
+       test_cmp expect actual
+'
+
+test_expect_failure 'grep --textconv: superproject .git/info/attributes does not affect submodules' '
+       reset_and_clean &&
+       test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
+       super_attr="$(git rev-parse --git-path info/attributes)" &&
+       test_when_finished "rm -f \"$super_attr\"" &&
+       echo "a diff=d2x" >"$super_attr" &&
+
+       cat >expect <<-\EOF &&
+       a:(1|2)x(3|4)
+       EOF
+       git grep --textconv --recurse-submodules x >actual &&
+       test_cmp expect actual
+'
+
+# Note: what currently prevents this test from passing is not that the
+# .gitattributes file from "./submodule" is being ignored, but that it is being
+# propagated to the nested "./submodule/sub" files.
+#
+test_expect_failure 'grep --textconv correctly reads submodule .gitattributes' '
+       reset_and_clean &&
+       test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
+       echo "a diff=d2x" >submodule/.gitattributes &&
+
+       cat >expect <<-\EOF &&
+       submodule/a:(1|2)x(3|4)
+       EOF
+       git grep --textconv --recurse-submodules x >actual &&
+       test_cmp expect actual
+'
+
+test_expect_failure 'grep --textconv correctly reads submodule .gitattributes (from index)' '
+       reset_and_clean &&
+       test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
+       echo "a diff=d2x" >submodule/.gitattributes &&
+       git -C submodule add .gitattributes &&
+       rm submodule/.gitattributes &&
+
+       cat >expect <<-\EOF &&
+       submodule/a:(1|2)x(3|4)
+       EOF
+       git grep --textconv --recurse-submodules x >actual &&
+       test_cmp expect actual
+'
+
+test_expect_failure 'grep --textconv correctly reads submodule .git/info/attributes' '
+       reset_and_clean &&
+       test_config_global diff.d2x.textconv "sed -e \"s/d/x/\"" &&
+
+       submodule_attr="$(git -C submodule rev-parse --path-format=absolute --git-path info/attributes)" &&
+       test_when_finished "rm -f \"$submodule_attr\"" &&
+       echo "a diff=d2x" >"$submodule_attr" &&
+
+       cat >expect <<-\EOF &&
+       submodule/a:(1|2)x(3|4)
+       EOF
+       git grep --textconv --recurse-submodules x >actual &&
+       test_cmp expect actual
+'
+
+test_expect_failure 'grep saves textconv cache in the appropriate repository' '
+       reset_and_clean &&
+       test_config_global diff.d2x_cached.textconv "sed -e \"s/d/x/\"" &&
+       test_config_global diff.d2x_cached.cachetextconv true &&
+       echo "a diff=d2x_cached" >submodule/.gitattributes &&
+
+       # We only read/write to the textconv cache when grepping from an OID,
+       # as the working tree file might have modifications.
+       git grep --textconv --cached --recurse-submodules x &&
+
+       super_textconv_cache="$(git rev-parse --git-path refs/notes/textconv/d2x_cached)" &&
+       sub_textconv_cache="$(git -C submodule rev-parse \
+                       --path-format=absolute --git-path refs/notes/textconv/d2x_cached)" &&
+       test_path_is_missing "$super_textconv_cache" &&
+       test_path_is_file "$sub_textconv_cache"
+'
+
 test_done