summaryrefslogtreecommitdiff
path: root/t/t7814-grep-recurse-submodules.sh
diff options
context:
space:
mode:
authorMatheus Tavares <matheus.bernardino@usp.br>2019-07-30 16:53:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-07-30 20:29:54 (GMT)
commit6a289d45c0e5d155f536d7c1f73c3b33690e92c6 (patch)
tree8df2d2154eb97939bd38f3d9a75b6643faa4b824 /t/t7814-grep-recurse-submodules.sh
parent1feeaaf26bff51996f9f96c6dc41ca0f95ab5fc4 (diff)
downloadgit-6a289d45c0e5d155f536d7c1f73c3b33690e92c6.zip
git-6a289d45c0e5d155f536d7c1f73c3b33690e92c6.tar.gz
git-6a289d45c0e5d155f536d7c1f73c3b33690e92c6.tar.bz2
grep: fix worktree case in submodules
Running git-grep with --recurse-submodules results in a cached grep for the submodules even when --cached is not used. This makes all modifications in submodules' tracked files be always ignored when grepping. Solve that making git-grep respect the cached option when invoking grep_cache() inside grep_submodule(). Also, add tests to ensure that the desired behavior is performed. Reported-by: Daniel Zaoui <jackdanielz@eyomi.org> Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> 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.sh21
1 files changed, 21 insertions, 0 deletions
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index 134a6945..48f2b13 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -392,4 +392,25 @@ test_expect_success 'grep --recurse-submodules with submodules without .gitmodul
test_cmp expect actual
'
+reset_and_clean () {
+ git reset --hard &&
+ git clean -fd &&
+ git submodule foreach --recursive 'git reset --hard' &&
+ git submodule foreach --recursive 'git clean -fd'
+}
+
+test_expect_success 'grep --recurse-submodules without --cached considers worktree modifications' '
+ reset_and_clean &&
+ echo "A modified line in submodule" >>submodule/a &&
+ echo "submodule/a:A modified line in submodule" >expect &&
+ git grep --recurse-submodules "A modified line in submodule" >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'grep --recurse-submodules with --cached ignores worktree modifications' '
+ reset_and_clean &&
+ echo "A modified line in submodule" >>submodule/a &&
+ test_must_fail git grep --recurse-submodules --cached "A modified line in submodule" >actual 2>&1 &&
+ test_must_be_empty actual
+'
test_done