When using the --recurse-submodules flag with a relative pathspec which
includes "..", an error is produced inside the child process spawned for a
submodule.  When creating the pathspec struct in the child, the ".." is
interpreted to mean "go up a directory" which causes an error stating that the
path ".." is outside of the repository.

While it is true that ".." is outside the scope of the submodule, it is
confusing to a user who originally invoked the command where ".." was indeed
still inside the scope of the superproject.  Since the child process luanched
for the submodule has some context that it is operating underneath a
superproject, this error could be avoided.

Signed-off-by: Brandon Williams <bmw...@google.com>
---
 t/t3007-ls-files-recurse-submodules.sh | 50 ++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/t/t3007-ls-files-recurse-submodules.sh 
b/t/t3007-ls-files-recurse-submodules.sh
index a5426171d..d8ab10866 100755
--- a/t/t3007-ls-files-recurse-submodules.sh
+++ b/t/t3007-ls-files-recurse-submodules.sh
@@ -188,6 +188,56 @@ test_expect_success '--recurse-submodules and pathspecs' '
        test_cmp expect actual
 '
 
+test_expect_failure '--recurse-submodules and relative paths' '
+       # From top works
+       cat >expect <<-\EOF &&
+       .gitmodules
+       a
+       b/b
+       h.txt
+       sib/file
+       sub/file
+       submodule/.gitmodules
+       submodule/c
+       submodule/f.TXT
+       submodule/g.txt
+       submodule/subsub/d
+       submodule/subsub/e.txt
+       EOF
+       git ls-files --recurse-submodules >actual &&
+       test_cmp expect actual &&
+
+       # Relative path to top errors out
+       cat >expect <<-\EOF &&
+       ../.gitmodules
+       ../a
+       b
+       ../h.txt
+       ../sib/file
+       ../sub/file
+       ../submodule/.gitmodules
+       ../submodule/c
+       ../submodule/f.TXT
+       ../submodule/g.txt
+       ../submodule/subsub/d
+       ../submodule/subsub/e.txt
+       EOF
+       git -C b ls-files --recurse-submodules -- .. >actual &&
+       test_cmp expect actual &&
+
+       # Relative path to submodule errors out
+       cat >expect <<-\EOF &&
+       ../submodule/.gitmodules
+       ../submodule/c
+       ../submodule/f.TXT
+       ../submodule/g.txt
+       ../submodule/subsub/d
+       ../submodule/subsub/e.txt
+       EOF
+       git -C b ls-files --recurse-submodules -- ../submodule >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success '--recurse-submodules does not support --error-unmatch' '
        test_must_fail git ls-files --recurse-submodules --error-unmatch 
2>actual &&
        test_i18ngrep "does not support --error-unmatch" actual
-- 
2.11.0.483.g087da7b7c-goog

Reply via email to