]> git.ipfire.org Git - thirdparty/git.git/commit - t/t7814-grep-recurse-submodules.sh
grep: fix bug when recursing with relative pathspec
authorBrandon Williams <bmwill@google.com>
Fri, 17 Mar 2017 17:22:55 +0000 (10:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Mar 2017 18:54:50 +0000 (11:54 -0700)
commitbe80a2392f5d10395bf934a066faeefdb6bb380a
treecba9bd04ba1db8b7d6fe382667b24acfc35ad636
parentb58a68c1c1874ff155699d82947c9f026f431cb3
grep: fix bug when recursing with relative pathspec

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 launched for the submodule has some context that it is operating
underneath a superproject, this error could be avoided.

This patch fixes the bug by passing the 'prefix' to the child process.
Now each child process that works on a submodule has two points of
reference to the superproject: (1) the 'super_prefix' which is the path
from the root of the superproject down to root of the submodule and (2)
the 'prefix' which is the path from the root of the superproject down to
the directory where the user invoked the git command.

With these two pieces of information a child process can correctly
interpret the pathspecs provided by the user as well as being able to
properly format its output relative to the directory the user invoked
the original command from.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
t/t7814-grep-recurse-submodules.sh