Merge branch 'rs/grep-color'
authorJunio C Hamano <gitster@pobox.com>
Thu, 30 Jun 2011 00:03:13 +0000 (17:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Jun 2011 00:03:13 +0000 (17:03 -0700)
* rs/grep-color:
grep: add --heading
grep: add --break
grep: fix coloring of hunk marks between files

1  2 
t/t7810-grep.sh
diff --combined t/t7810-grep.sh
index 6379ad60bcb9b5b56eb773b5a987745356c24df6,1227fa69b4840d6eb8f9e915d911fcddb55076dd..a29ae45b399f89123f886f5b35580bcdc0e803f1
@@@ -658,9 -658,9 +658,9 @@@ test_expect_success LIBPCRE 'grep -P -
  '
  
  test_expect_success LIBPCRE 'grep -P -i pattern' '
 -      {
 -              echo "hello.c:  printf(\"Hello world.\n\");"
 -      } >expected &&
 +      cat >expected <<-EOF &&
 +      hello.c:        printf("Hello world.\n");
 +      EOF
        git grep -P -i "PRINTF\([^\d]+\)" hello.c >actual &&
        test_cmp expected actual
  '
@@@ -716,4 -716,99 +716,99 @@@ test_expect_success LIBPCRE 'grep -G -
        test_cmp expected actual
  '
  
+ test_config() {
+       git config "$1" "$2" &&
+       test_when_finished "git config --unset $1"
+ }
+ cat >expected <<EOF
+ hello.c<RED>:<RESET>int main(int argc, const char **argv)
+ hello.c<RED>-<RESET>{
+ <RED>--<RESET>
+ hello.c<RED>:<RESET>  /* char ?? */
+ hello.c<RED>-<RESET>}
+ <RED>--<RESET>
+ hello_world<RED>:<RESET>Hello_world
+ hello_world<RED>-<RESET>HeLLo_world
+ EOF
+ test_expect_success 'grep --color, separator' '
+       test_config color.grep.context          normal &&
+       test_config color.grep.filename         normal &&
+       test_config color.grep.function         normal &&
+       test_config color.grep.linenumber       normal &&
+       test_config color.grep.match            normal &&
+       test_config color.grep.selected         normal &&
+       test_config color.grep.separator        red &&
+       git grep --color=always -A1 -e char -e lo_w hello.c hello_world |
+       test_decode_color >actual &&
+       test_cmp expected actual
+ '
+ cat >expected <<EOF
+ hello.c:int main(int argc, const char **argv)
+ hello.c:      /* char ?? */
+ hello_world:Hello_world
+ EOF
+ test_expect_success 'grep --break' '
+       git grep --break -e char -e lo_w hello.c hello_world >actual &&
+       test_cmp expected actual
+ '
+ cat >expected <<EOF
+ hello.c:int main(int argc, const char **argv)
+ hello.c-{
+ --
+ hello.c:      /* char ?? */
+ hello.c-}
+ hello_world:Hello_world
+ hello_world-HeLLo_world
+ EOF
+ test_expect_success 'grep --break with context' '
+       git grep --break -A1 -e char -e lo_w hello.c hello_world >actual &&
+       test_cmp expected actual
+ '
+ cat >expected <<EOF
+ hello.c
+ int main(int argc, const char **argv)
+       /* char ?? */
+ hello_world
+ Hello_world
+ EOF
+ test_expect_success 'grep --heading' '
+       git grep --heading -e char -e lo_w hello.c hello_world >actual &&
+       test_cmp expected actual
+ '
+ cat >expected <<EOF
+ <BOLD;GREEN>hello.c<RESET>
+ 2:int main(int argc, const <BLACK;BYELLOW>char<RESET> **argv)
+ 6:    /* <BLACK;BYELLOW>char<RESET> ?? */
+ <BOLD;GREEN>hello_world<RESET>
+ 3:Hel<BLACK;BYELLOW>lo_w<RESET>orld
+ EOF
+ test_expect_success 'mimic ack-grep --group' '
+       test_config color.grep.context          normal &&
+       test_config color.grep.filename         "bold green" &&
+       test_config color.grep.function         normal &&
+       test_config color.grep.linenumber       normal &&
+       test_config color.grep.match            "black yellow" &&
+       test_config color.grep.selected         normal &&
+       test_config color.grep.separator        normal &&
+       git grep --break --heading -n --color \
+               -e char -e lo_w hello.c hello_world |
+       test_decode_color >actual &&
+       test_cmp expected actual
+ '
  test_done