From: Chris Packham <judge.packham@gmail.com>
To: git@vger.kernel.org
Cc: Chris Packham <judge.packham@gmail.com>
Subject: [RFC PATCH 1/2] contrib: add git-submodule-grep.sh
Date: Thu, 23 Sep 2010 14:17:06 -0700 [thread overview]
Message-ID: <1285276627-7907-2-git-send-email-judge.packham@gmail.com> (raw)
In-Reply-To: <1285276627-7907-1-git-send-email-judge.packham@gmail.com>
A simple wrapper around 'git grep' that is submodule aware.
The advantage of this over "git submodule foreach 'git grep <pattern>'" is
that the results are presented with a path relative to the current
directory. Also this script will work from any subdirectory of any submodule
in the current superproject.
Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
contrib/git-submodule-grep.sh | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
create mode 100755 contrib/git-submodule-grep.sh
diff --git a/contrib/git-submodule-grep.sh b/contrib/git-submodule-grep.sh
new file mode 100755
index 0000000..407fdb0
--- /dev/null
+++ b/contrib/git-submodule-grep.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# Copyright (c) 2010, Chris Packham
+# Wrapper for git grep that is submodule aware
+
+SUBDIRECTORY_OK="yes"
+. git-sh-setup
+
+submodule_root_relative()
+{
+ ceiling="$HOME"
+ while test ! -e "$cdup.gitmodules"; do
+ cdup="$cdup../"
+ if test "$(cd $cdup && pwd)" == "$ceiling"; then
+ echo >&2 "fatal: failed to find superproject root,"
+ echo >&2 " stopped searching at $ceiling."
+ exit 1
+ fi
+ done
+ echo "$cdup"
+}
+
+submodule_root()
+{
+ (cd "$(submodule_root_relative)" && pwd)
+}
+
+# we don't do anything with the arg but we should check that we
+# have something to pass to git grep
+test $# -lt 1 && die "fatal: no pattern given."
+
+prefix="$(submodule_root_relative)" || exit 1
+(cd "./$prefix"; \
+ git submodule --quiet foreach \
+ "git --no-pager grep $@ | sed s\"|.*|$prefix\$path/&|\" || true") \
+ | git_pager
--
1.7.3.dirty
next prev parent reply other threads:[~2010-09-23 21:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-23 21:17 [RFC PATCH 0/2] submodule aware grep Chris Packham
2010-09-23 21:17 ` Chris Packham [this message]
2010-09-23 21:17 ` [RFC PATCH 2/2] submodule: add grep command Chris Packham
2010-09-24 13:47 ` [RFC PATCH 0/2] submodule aware grep Heiko Voigt
2010-09-24 16:07 ` Chris Packham
2010-09-24 17:10 ` Jens Lehmann
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=1285276627-7907-2-git-send-email-judge.packham@gmail.com \
--to=judge.packham@gmail.com \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).