All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brandon Williams <bmwill@google.com>
To: git@vger.kernel.org
Cc: Brandon Williams <bmwill@google.com>,
	sbeller@google.com, pclouds@gmail.com
Subject: [PATCH 3/5] grep: fix bug when recuring with relative pathspec
Date: Fri, 24 Feb 2017 15:50:58 -0800	[thread overview]
Message-ID: <20170224235100.52627-4-bmwill@google.com> (raw)
In-Reply-To: <20170224235100.52627-1-bmwill@google.com>

Fix a bug which causes a child process for a submodule to error out when
a relative pathspec with a ".." is provided in the superproject.

While at it, correctly construct the super-prefix to be used in a
submodule when not at the root of the repository.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 builtin/grep.c                     | 8 ++++++--
 t/t7814-grep-recurse-submodules.sh | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index 2c727ef49..65f3413d1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -538,6 +538,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
 	int status, i;
 	const char *end_of_base;
 	const char *name;
+	struct strbuf buf = STRBUF_INIT;
 	struct work_item *w = opt->output_priv;
 
 	end_of_base = strchr(gs->name, ':');
@@ -550,9 +551,11 @@ static int grep_submodule_launch(struct grep_opt *opt,
 	argv_array_push(&cp.env_array, GIT_DIR_ENVIRONMENT);
 
 	/* Add super prefix */
+	quote_path_relative(name, opt->prefix, &buf);
 	argv_array_pushf(&cp.args, "--super-prefix=%s%s/",
 			 super_prefix ? super_prefix : "",
-			 name);
+			 buf.buf);
+	strbuf_release(&buf);
 	argv_array_push(&cp.args, "grep");
 
 	/*
@@ -1199,7 +1202,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 
 	parse_pathspec(&pathspec, 0,
 		       PATHSPEC_PREFER_CWD |
-		       (opt.max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0),
+		       (opt.max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0) |
+		       (super_prefix ? PATHSPEC_FROMROOT : 0),
 		       prefix, argv + i);
 	pathspec.max_depth = opt.max_depth;
 	pathspec.recursive = 1;
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index 418ba68fe..e0932b2b7 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -227,7 +227,7 @@ test_expect_success 'grep history with moved submoules' '
 	test_cmp expect actual
 '
 
-test_expect_failure 'grep using relative path' '
+test_expect_success 'grep using relative path' '
 	test_when_finished "rm -rf parent sub" &&
 	git init sub &&
 	echo "foobar" >sub/file &&
-- 
2.11.0.483.g087da7b7c-goog


  parent reply	other threads:[~2017-02-24 23:51 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-24 23:50 [PATCH 0/5] recursing submodules with relative pathspec (grep and ls-files) Brandon Williams
2017-02-24 23:50 ` [PATCH 1/5] grep: illustrate bug when recursing with relative pathspec Brandon Williams
2017-02-26  9:53   ` Duy Nguyen
2017-02-27 18:14     ` Brandon Williams
2017-02-24 23:50 ` [PATCH 2/5] pathspec: add PATHSPEC_FROMROOT flag Brandon Williams
2017-02-25  0:31   ` Stefan Beller
2017-02-24 23:50 ` Brandon Williams [this message]
2017-02-28 21:04   ` [PATCH 3/5] grep: fix bug when recuring with relative pathspec Junio C Hamano
2017-03-02 18:00     ` Brandon Williams
2017-02-24 23:50 ` [PATCH 4/5] ls-files: illustrate bug when recursing " Brandon Williams
2017-02-24 23:51 ` [PATCH 5/5] ls-files: fix bug when recuring " Brandon Williams
2017-02-28 21:07   ` Junio C Hamano
2017-03-02 18:01     ` Brandon Williams
2017-02-27 17:52 ` [PATCH 0/5] recursing submodules with relative pathspec (grep and ls-files) Brandon Williams
2017-03-06 23:07 ` [RFC PATCH] grep: fix bug when recursing with relative pathspec Brandon Williams
2017-03-14 22:10 ` [PATCH v2 0/4] recursing submodules with relative pathspec (grep and ls-files) Brandon Williams
2017-03-14 22:10   ` [PATCH v2 1/4] grep: fix help text typo Brandon Williams
2017-03-14 22:49     ` Stefan Beller
2017-03-15  0:20       ` Brandon Williams
2017-03-14 22:10   ` [PATCH v2 2/4] setup: allow for prefix to be passed to git commands Brandon Williams
2017-03-14 22:28     ` Johannes Schindelin
2017-03-14 22:35       ` Brandon Williams
2017-03-14 22:10   ` [PATCH v2 3/4] grep: fix bug when recursing with relative pathspec Brandon Williams
2017-03-14 23:03     ` Stefan Beller
2017-03-14 22:11   ` [PATCH v2 4/4] ls-files: " Brandon Williams
2017-03-14 23:06     ` Stefan Beller
2017-03-15 17:02       ` Brandon Williams
2017-03-17 17:22   ` [PATCH v3 0/5] recursing submodules with relative pathspec (grep and ls-files) Brandon Williams
2017-03-17 17:22     ` [PATCH v3 1/5] grep: fix help text typo Brandon Williams
2017-03-17 17:22     ` [PATCH v3 2/5] setup: allow for prefix to be passed to git commands Brandon Williams
2017-03-17 19:07       ` Stefan Beller
2017-03-17 19:08         ` Brandon Williams
2017-03-17 19:10           ` Stefan Beller
2017-03-17 19:17             ` Brandon Williams
2017-03-17 19:17         ` Junio C Hamano
2017-03-17 19:21           ` Brandon Williams
2017-03-17 20:30             ` Junio C Hamano
2017-03-17 21:00               ` Brandon Williams
2017-03-17 21:25                 ` Junio C Hamano
2017-03-20 22:34                   ` Brandon Williams
2017-03-21 16:56                     ` Junio C Hamano
2017-03-28 23:58                     ` Stefan Beller
2017-03-17 17:22     ` [PATCH v3 3/5] grep: fix bug when recursing with relative pathspec Brandon Williams
2017-03-21 11:47       ` Duy Nguyen
2017-03-21 17:56         ` Junio C Hamano
2017-03-22 21:46         ` Brandon Williams
2017-03-17 17:22     ` [PATCH v3 4/5] ls-files: fix typo in variable name Brandon Williams
2017-03-17 17:22     ` [PATCH v3 5/5] ls-files: fix bug when recursing with relative pathspec Brandon Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170224235100.52627-4-bmwill@google.com \
    --to=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.