summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>2011-08-01 17:20:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-08-01 23:09:15 (GMT)
commitba8ea7496f2b95c49fccb72ed6b332afbd865e7b (patch)
treec52a2d2007a2e209813df918dede0b05bbd08be8 /t
parentb35acb53458d0f99ba2400b902980b35e5acc2d3 (diff)
downloadgit-ba8ea7496f2b95c49fccb72ed6b332afbd865e7b.zip
git-ba8ea7496f2b95c49fccb72ed6b332afbd865e7b.tar.gz
git-ba8ea7496f2b95c49fccb72ed6b332afbd865e7b.tar.bz2
grep: add option to show whole function as context
Add a new option, -W, to show the whole surrounding function of a match. It uses the same regular expressions as -p and diff to find the beginning of sections. Currently it will not display comments in front of a function, but those that are following one. Despite this shortcoming it is already useful, e.g. to simply see a more complete applicable context or to extract whole functions. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-xt/t7810-grep.sh14
1 files changed, 14 insertions, 0 deletions
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index a29ae45..0d60016 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -509,6 +509,20 @@ test_expect_success 'grep -p -B5' '
test_cmp expected actual
'
+cat >expected <<EOF
+hello.c=int main(int argc, const char **argv)
+hello.c-{
+hello.c- printf("Hello world.\n");
+hello.c: return 0;
+hello.c- /* char ?? */
+hello.c-}
+EOF
+
+test_expect_success 'grep -W' '
+ git grep -W return >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'grep from a subdirectory to search wider area (1)' '
mkdir -p s &&
(