Skip to content

Commit

Permalink
vgrep: don't fail recursing into git submodules
Browse files Browse the repository at this point in the history
Reported by @darnir.
  • Loading branch information
vrothberg committed Sep 11, 2016
1 parent 29c8a4c commit f4045fc
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions vgrep
Original file line number Diff line number Diff line change
Expand Up @@ -714,14 +714,14 @@ def print_slocs(slocs, indices, options):
bold=(lcount % 2))


def execute(cmd, failOK=False, env=None):
def execute(cmd, failOK=False, env=None, cwd=None):
"""
Execute %cmd and return stdout. Exit in case of error.
"""
stdout = ""
cmd = shlex.split(cmd)
try:
stdout = subp.check_output(cmd, stderr=subp.STDOUT, shell=False, env=env)
stdout = subp.check_output(cmd, stderr=subp.STDOUT, env=env, cwd=cwd)
stdout = stdout.decode(errors='replace')
except subp.CalledProcessError as fail:
if failOK:
Expand Down Expand Up @@ -782,8 +782,7 @@ def grep(grep_args, nogit, nogitsubmodules, files=None):
submodule = os.path.relpath(submodule, cwd)

# Start grep within the submodule
sub_grep_cmd = "cd %s && %s" % (quote(submodule), git_grep_cmd)
lines = execute(sub_grep_cmd, failOK=True).rsplit("\n")
lines = execute(git_grep_cmd, failOK=True, cwd=submodule).rsplit("\n")
# Prepend the relative submodule path to each line
for line in [x for x in lines if x]:
git_grep_results.append(os.path.join(submodule, line))
Expand Down

0 comments on commit f4045fc

Please sign in to comment.