summaryrefslogtreecommitdiff
path: root/t/t7814-grep-recurse-submodules.sh
diff options
context:
space:
mode:
authorAntonio Ospite <ao2@ao2.it>2018-10-25 16:18:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-10-31 06:01:30 (GMT)
commit76e9bdc437ca3111883eb57a479e5d8f582dd670 (patch)
tree70442b23252b1c0a3441d41dd9c62e955a3b4c9f /t/t7814-grep-recurse-submodules.sh
parentb5c259f226ba06f64b399ff4c6b843542352395f (diff)
downloadgit-76e9bdc437ca3111883eb57a479e5d8f582dd670.zip
git-76e9bdc437ca3111883eb57a479e5d8f582dd670.tar.gz
git-76e9bdc437ca3111883eb57a479e5d8f582dd670.tar.bz2
submodule: support reading .gitmodules when it's not in the working tree
When the .gitmodules file is not available in the working tree, try using the content from the index and from the current branch. This covers the case when the file is part of the repository but for some reason it is not checked out, for example because of a sparse checkout. This makes it possible to use at least the 'git submodule' commands which *read* the gitmodules configuration file without fully populating the working tree. Writing to .gitmodules will still require that the file is checked out, so check for that before calling config_set_in_gitmodules_file_gently. Add a similar check also in git-submodule.sh::cmd_add() to anticipate the eventual failure of the "git submodule add" command when .gitmodules is not safely writeable; this prevents the command from leaving the repository in a spurious state (e.g. the submodule repository was cloned but .gitmodules was not updated because config_set_in_gitmodules_file_gently failed). Moreover, since config_from_gitmodules() now accesses the global object store, it is necessary to protect all code paths which call the function against concurrent access to the global object store. Currently this only happens in builtin/grep.c::grep_submodules(), so call grep_read_lock() before invoking code involving config_from_gitmodules(). Finally, add t7418-submodule-sparse-gitmodules.sh to verify that reading from .gitmodules succeeds and that writing to it fails when the file is not checked out. NOTE: there is one rare case where this new feature does not work properly yet: nested submodules without .gitmodules in their working tree. This has been documented with a warning and a test_expect_failure item in t7814, and in this case the current behavior is not altered: no config is read. Signed-off-by: Antonio Ospite <ao2@ao2.it> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t7814-grep-recurse-submodules.sh')
-rwxr-xr-xt/t7814-grep-recurse-submodules.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index 7184113..fa475d5 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -380,4 +380,20 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon
fi
'
+# Recursing down into nested submodules which do not have .gitmodules in their
+# working tree does not work yet. This is because config_from_gitmodules()
+# uses get_oid() and the latter is still not able to get objects from an
+# arbitrary repository (the nested submodule, in this case).
+test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
+ test_when_finished "git -C submodule checkout .gitmodules" &&
+ rm submodule/.gitmodules &&
+ git grep --recurse-submodules -e "(.|.)[\d]" >actual &&
+ cat >expect <<-\EOF &&
+ a:(1|2)d(3|4)
+ submodule/a:(1|2)d(3|4)
+ submodule/sub/a:(1|2)d(3|4)
+ EOF
+ test_cmp expect actual
+'
+
test_done