t5545: enhance test coverage when no http server is installed
[gitweb.git] / t / t7814-grep-recurse-submodules.sh
index 67247a01d6dd2bd22970cd05f7b7088e9261186d..5b6eb3a65e26263db526c2e891ae01a4578bf48e 100755 (executable)
@@ -227,6 +227,81 @@ test_expect_success 'grep history with moved submoules' '
        test_cmp expect actual
 '
 
+test_expect_success 'grep using relative path' '
+       test_when_finished "rm -rf parent sub" &&
+       git init sub &&
+       echo "foobar" >sub/file &&
+       git -C sub add file &&
+       git -C sub commit -m "add file" &&
+
+       git init parent &&
+       echo "foobar" >parent/file &&
+       git -C parent add file &&
+       mkdir parent/src &&
+       echo "foobar" >parent/src/file2 &&
+       git -C parent add src/file2 &&
+       git -C parent submodule add ../sub &&
+       git -C parent commit -m "add files and submodule" &&
+
+       # From top works
+       cat >expect <<-\EOF &&
+       file:foobar
+       src/file2:foobar
+       sub/file:foobar
+       EOF
+       git -C parent grep --recurse-submodules -e "foobar" >actual &&
+       test_cmp expect actual &&
+
+       # Relative path to top
+       cat >expect <<-\EOF &&
+       ../file:foobar
+       file2:foobar
+       ../sub/file:foobar
+       EOF
+       git -C parent/src grep --recurse-submodules -e "foobar" -- .. >actual &&
+       test_cmp expect actual &&
+
+       # Relative path to submodule
+       cat >expect <<-\EOF &&
+       ../sub/file:foobar
+       EOF
+       git -C parent/src grep --recurse-submodules -e "foobar" -- ../sub >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'grep from a subdir' '
+       test_when_finished "rm -rf parent sub" &&
+       git init sub &&
+       echo "foobar" >sub/file &&
+       git -C sub add file &&
+       git -C sub commit -m "add file" &&
+
+       git init parent &&
+       mkdir parent/src &&
+       echo "foobar" >parent/src/file &&
+       git -C parent add src/file &&
+       git -C parent submodule add ../sub src/sub &&
+       git -C parent submodule add ../sub sub &&
+       git -C parent commit -m "add files and submodules" &&
+
+       # Verify grep from root works
+       cat >expect <<-\EOF &&
+       src/file:foobar
+       src/sub/file:foobar
+       sub/file:foobar
+       EOF
+       git -C parent grep --recurse-submodules -e "foobar" >actual &&
+       test_cmp expect actual &&
+
+       # Verify grep from a subdir works
+       cat >expect <<-\EOF &&
+       file:foobar
+       sub/file:foobar
+       EOF
+       git -C parent/src grep --recurse-submodules -e "foobar" >actual &&
+       test_cmp expect actual
+'
+
 test_incompatible_with_recurse_submodules ()
 {
        test_expect_success "--recurse-submodules and $1 are incompatible" "