René Scharfe | aca20dd | 2010-05-22 23:26:39 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git grep in binary files' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup' " |
Ævar Arnfjörð Bjarmason | 12fc32f | 2017-05-20 21:42:16 +0000 | [diff] [blame] | 8 | echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a && |
René Scharfe | aca20dd | 2010-05-22 23:26:39 +0200 | [diff] [blame] | 9 | git add a && |
| 10 | git commit -m. |
| 11 | " |
| 12 | |
| 13 | test_expect_success 'git grep ina a' ' |
| 14 | echo Binary file a matches >expect && |
| 15 | git grep ina a >actual && |
| 16 | test_cmp expect actual |
| 17 | ' |
| 18 | |
| 19 | test_expect_success 'git grep -ah ina a' ' |
| 20 | git grep -ah ina a >actual && |
| 21 | test_cmp a actual |
| 22 | ' |
| 23 | |
| 24 | test_expect_success 'git grep -I ina a' ' |
René Scharfe | aca20dd | 2010-05-22 23:26:39 +0200 | [diff] [blame] | 25 | test_must_fail git grep -I ina a >actual && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 26 | test_must_be_empty actual |
René Scharfe | aca20dd | 2010-05-22 23:26:39 +0200 | [diff] [blame] | 27 | ' |
| 28 | |
René Scharfe | c30c10c | 2010-05-22 23:29:35 +0200 | [diff] [blame] | 29 | test_expect_success 'git grep -c ina a' ' |
| 30 | echo a:1 >expect && |
| 31 | git grep -c ina a >actual && |
| 32 | test_cmp expect actual |
| 33 | ' |
| 34 | |
René Scharfe | 321ffcc | 2010-05-22 23:30:48 +0200 | [diff] [blame] | 35 | test_expect_success 'git grep -l ina a' ' |
| 36 | echo a >expect && |
| 37 | git grep -l ina a >actual && |
| 38 | test_cmp expect actual |
| 39 | ' |
| 40 | |
René Scharfe | aca20dd | 2010-05-22 23:26:39 +0200 | [diff] [blame] | 41 | test_expect_success 'git grep -L bar a' ' |
| 42 | echo a >expect && |
| 43 | git grep -L bar a >actual && |
| 44 | test_cmp expect actual |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'git grep -q ina a' ' |
René Scharfe | aca20dd | 2010-05-22 23:26:39 +0200 | [diff] [blame] | 48 | git grep -q ina a >actual && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 49 | test_must_be_empty actual |
René Scharfe | aca20dd | 2010-05-22 23:26:39 +0200 | [diff] [blame] | 50 | ' |
| 51 | |
René Scharfe | 1baddf4 | 2010-05-22 23:32:43 +0200 | [diff] [blame] | 52 | test_expect_success 'git grep -F ile a' ' |
| 53 | git grep -F ile a |
| 54 | ' |
| 55 | |
René Scharfe | 52d799a | 2010-05-22 23:34:06 +0200 | [diff] [blame] | 56 | test_expect_success 'git grep -Fi iLE a' ' |
| 57 | git grep -Fi iLE a |
| 58 | ' |
| 59 | |
René Scharfe | f96e567 | 2010-05-22 23:35:07 +0200 | [diff] [blame] | 60 | # This test actually passes on platforms where regexec() supports the |
| 61 | # flag REG_STARTEND. |
Ævar Arnfjörð Bjarmason | 7e36de5 | 2010-08-17 09:24:41 +0000 | [diff] [blame] | 62 | test_expect_success 'git grep ile a' ' |
René Scharfe | f96e567 | 2010-05-22 23:35:07 +0200 | [diff] [blame] | 63 | git grep ile a |
| 64 | ' |
| 65 | |
| 66 | test_expect_failure 'git grep .fi a' ' |
| 67 | git grep .fi a |
| 68 | ' |
| 69 | |
Jeff King | 41b59bf | 2012-02-02 03:21:02 -0500 | [diff] [blame] | 70 | test_expect_success 'grep respects binary diff attribute' ' |
| 71 | echo text >t && |
| 72 | git add t && |
| 73 | echo t:text >expect && |
| 74 | git grep text t >actual && |
| 75 | test_cmp expect actual && |
| 76 | echo "t -diff" >.gitattributes && |
| 77 | echo "Binary file t matches" >expect && |
| 78 | git grep text t >actual && |
| 79 | test_cmp expect actual |
| 80 | ' |
| 81 | |
Nguyễn Thái Ngọc Duy | 55c6168 | 2012-10-12 17:49:38 +0700 | [diff] [blame] | 82 | test_expect_success 'grep --cached respects binary diff attribute' ' |
| 83 | git grep --cached text t >actual && |
| 84 | test_cmp expect actual |
| 85 | ' |
| 86 | |
| 87 | test_expect_success 'grep --cached respects binary diff attribute (2)' ' |
| 88 | git add .gitattributes && |
| 89 | rm .gitattributes && |
| 90 | git grep --cached text t >actual && |
| 91 | test_when_finished "git rm --cached .gitattributes" && |
| 92 | test_when_finished "git checkout .gitattributes" && |
| 93 | test_cmp expect actual |
| 94 | ' |
| 95 | |
| 96 | test_expect_success 'grep revision respects binary diff attribute' ' |
| 97 | git commit -m new && |
| 98 | echo "Binary file HEAD:t matches" >expect && |
| 99 | git grep text HEAD -- t >actual && |
| 100 | test_when_finished "git reset HEAD^" && |
| 101 | test_cmp expect actual |
| 102 | ' |
| 103 | |
Jeff King | 41b59bf | 2012-02-02 03:21:02 -0500 | [diff] [blame] | 104 | test_expect_success 'grep respects not-binary diff attribute' ' |
| 105 | echo binQary | q_to_nul >b && |
| 106 | git add b && |
| 107 | echo "Binary file b matches" >expect && |
| 108 | git grep bin b >actual && |
| 109 | test_cmp expect actual && |
| 110 | echo "b diff" >.gitattributes && |
| 111 | echo "b:binQary" >expect && |
Lars Schneider | a0578e0 | 2016-02-17 09:57:46 +0100 | [diff] [blame] | 112 | git grep bin b >actual.raw && |
| 113 | nul_to_q <actual.raw >actual && |
Jeff King | 41b59bf | 2012-02-02 03:21:02 -0500 | [diff] [blame] | 114 | test_cmp expect actual |
| 115 | ' |
| 116 | |
Michael J Gruber | 97f6a9c | 2013-05-10 17:10:14 +0200 | [diff] [blame] | 117 | cat >nul_to_q_textconv <<'EOF' |
| 118 | #!/bin/sh |
| 119 | "$PERL_PATH" -pe 'y/\000/Q/' < "$1" |
| 120 | EOF |
| 121 | chmod +x nul_to_q_textconv |
| 122 | |
| 123 | test_expect_success 'setup textconv filters' ' |
| 124 | echo a diff=foo >.gitattributes && |
| 125 | git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv |
| 126 | ' |
| 127 | |
| 128 | test_expect_success 'grep does not honor textconv' ' |
| 129 | test_must_fail git grep Qfile |
| 130 | ' |
| 131 | |
Jeff King | 335ec3b | 2013-05-10 17:10:15 +0200 | [diff] [blame] | 132 | test_expect_success 'grep --textconv honors textconv' ' |
Ævar Arnfjörð Bjarmason | 12fc32f | 2017-05-20 21:42:16 +0000 | [diff] [blame] | 133 | echo "a:binaryQfileQm[*]cQ*æQð" >expect && |
Michael J Gruber | 97f6a9c | 2013-05-10 17:10:14 +0200 | [diff] [blame] | 134 | git grep --textconv Qfile >actual && |
| 135 | test_cmp expect actual |
| 136 | ' |
| 137 | |
| 138 | test_expect_success 'grep --no-textconv does not honor textconv' ' |
| 139 | test_must_fail git grep --no-textconv Qfile |
| 140 | ' |
| 141 | |
Michael J Gruber | afa15f3 | 2013-05-10 17:10:16 +0200 | [diff] [blame] | 142 | test_expect_success 'grep --textconv blob honors textconv' ' |
Ævar Arnfjörð Bjarmason | 12fc32f | 2017-05-20 21:42:16 +0000 | [diff] [blame] | 143 | echo "HEAD:a:binaryQfileQm[*]cQ*æQð" >expect && |
Michael J Gruber | 97f6a9c | 2013-05-10 17:10:14 +0200 | [diff] [blame] | 144 | git grep --textconv Qfile HEAD:a >actual && |
| 145 | test_cmp expect actual |
| 146 | ' |
| 147 | |
René Scharfe | aca20dd | 2010-05-22 23:26:39 +0200 | [diff] [blame] | 148 | test_done |