| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='log --grep/--author/--regexp-ignore-case/-S/-G' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_log () { |
| 8 | expect=$1 |
| 9 | kind=$2 |
| 10 | needle=$3 |
| 11 | shift 3 |
| 12 | rest=$@ |
| 13 | |
| 14 | case $kind in |
| 15 | --*) |
| 16 | opt=$kind=$needle |
| 17 | ;; |
| 18 | *) |
| 19 | opt=$kind$needle |
| 20 | ;; |
| 21 | esac |
| 22 | case $expect in |
| 23 | expect_nomatch) |
| 24 | match=nomatch |
| 25 | ;; |
| 26 | *) |
| 27 | match=match |
| 28 | ;; |
| 29 | esac |
| 30 | |
| 31 | test_expect_success "log $kind${rest:+ $rest} ($match)" " |
| 32 | git log $rest $opt --format=%H >actual && |
| 33 | test_cmp $expect actual |
| 34 | " |
| 35 | } |
| 36 | |
| 37 | # test -i and --regexp-ignore-case and expect both to behave the same way |
| 38 | test_log_icase () { |
| 39 | test_log $@ --regexp-ignore-case |
| 40 | test_log $@ -i |
| 41 | } |
| 42 | |
| 43 | test_expect_success setup ' |
| 44 | >expect_nomatch && |
| 45 | |
| 46 | >file && |
| 47 | git add file && |
| 48 | test_tick && |
| 49 | git commit -m initial && |
| 50 | git rev-parse --verify HEAD >expect_initial && |
| 51 | |
| 52 | echo Picked >file && |
| 53 | git add file && |
| 54 | test_tick && |
| 55 | git commit --author="Another Person <another@example.com>" -m second && |
| 56 | git rev-parse --verify HEAD >expect_second |
| 57 | ' |
| 58 | |
| 59 | test_expect_success 'usage' ' |
| 60 | test_expect_code 129 git log -S 2>err && |
| 61 | test_grep "switch.*requires a value" err && |
| 62 | |
| 63 | test_expect_code 129 git log -G 2>err && |
| 64 | test_grep "switch.*requires a value" err && |
| 65 | |
| 66 | test_expect_code 128 git log -Gregex -Sstring 2>err && |
| 67 | grep "cannot be used together" err && |
| 68 | |
| 69 | test_expect_code 128 git log -Gregex --find-object=HEAD 2>err && |
| 70 | grep "cannot be used together" err && |
| 71 | |
| 72 | test_expect_code 128 git log -Sstring --find-object=HEAD 2>err && |
| 73 | grep "cannot be used together" err && |
| 74 | |
| 75 | test_expect_code 128 git log --pickaxe-all --find-object=HEAD 2>err && |
| 76 | grep "cannot be used together" err |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'usage: --pickaxe-regex' ' |
| 80 | test_expect_code 128 git log -Gregex --pickaxe-regex 2>err && |
| 81 | grep "cannot be used together" err |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'usage: --no-pickaxe-regex' ' |
| 85 | cat >expect <<-\EOF && |
| 86 | fatal: unrecognized argument: --no-pickaxe-regex |
| 87 | EOF |
| 88 | |
| 89 | test_expect_code 128 git log -Sstring --no-pickaxe-regex 2>actual && |
| 90 | test_cmp expect actual && |
| 91 | |
| 92 | test_expect_code 128 git log -Gstring --no-pickaxe-regex 2>err && |
| 93 | test_cmp expect actual |
| 94 | ' |
| 95 | |
| 96 | test_expect_success 'usage: -G and -S with empty argument' ' |
| 97 | cat >expect <<-\EOF && |
| 98 | error: -S requires a non-empty argument |
| 99 | EOF |
| 100 | |
| 101 | test_expect_code 129 git log -S "" 2>actual && |
| 102 | test_cmp expect actual && |
| 103 | |
| 104 | cat >expect <<-\EOF && |
| 105 | error: -G requires a non-empty argument |
| 106 | EOF |
| 107 | |
| 108 | test_expect_code 129 git log -G "" 2>actual && |
| 109 | test_cmp expect actual |
| 110 | ' |
| 111 | |
| 112 | test_log expect_initial --grep initial |
| 113 | test_log expect_nomatch --grep InItial |
| 114 | test_log_icase expect_initial --grep InItial |
| 115 | test_log_icase expect_nomatch --grep initail |
| 116 | |
| 117 | test_log expect_second --author Person |
| 118 | test_log expect_nomatch --author person |
| 119 | test_log_icase expect_second --author person |
| 120 | test_log_icase expect_nomatch --author spreon |
| 121 | |
| 122 | test_log expect_nomatch -G picked |
| 123 | test_log expect_second -G Picked |
| 124 | test_log_icase expect_nomatch -G pickle |
| 125 | test_log_icase expect_second -G picked |
| 126 | |
| 127 | test_expect_success 'log -G --textconv (missing textconv tool)' ' |
| 128 | echo "* diff=test" >.gitattributes && |
| 129 | test_must_fail git -c diff.test.textconv=missing log -Gfoo && |
| 130 | rm .gitattributes |
| 131 | ' |
| 132 | |
| 133 | test_expect_success 'log -G --no-textconv (missing textconv tool)' ' |
| 134 | echo "* diff=test" >.gitattributes && |
| 135 | git -c diff.test.textconv=missing log -Gfoo --no-textconv >actual && |
| 136 | test_cmp expect_nomatch actual && |
| 137 | rm .gitattributes |
| 138 | ' |
| 139 | |
| 140 | test_log expect_nomatch -S picked |
| 141 | test_log expect_second -S Picked |
| 142 | test_log_icase expect_second -S picked |
| 143 | test_log_icase expect_nomatch -S pickle |
| 144 | |
| 145 | test_log expect_nomatch -S p.cked --pickaxe-regex |
| 146 | test_log expect_second -S P.cked --pickaxe-regex |
| 147 | test_log_icase expect_second -S p.cked --pickaxe-regex |
| 148 | test_log_icase expect_nomatch -S p.ckle --pickaxe-regex |
| 149 | |
| 150 | test_expect_success 'log -S --textconv (missing textconv tool)' ' |
| 151 | echo "* diff=test" >.gitattributes && |
| 152 | test_must_fail git -c diff.test.textconv=missing log -Sfoo && |
| 153 | rm .gitattributes |
| 154 | ' |
| 155 | |
| 156 | test_expect_success 'log -S --no-textconv (missing textconv tool)' ' |
| 157 | echo "* diff=test" >.gitattributes && |
| 158 | git -c diff.test.textconv=missing log -Sfoo --no-textconv >actual && |
| 159 | test_cmp expect_nomatch actual && |
| 160 | rm .gitattributes |
| 161 | ' |
| 162 | |
| 163 | test_expect_success 'setup log -[GS] plain & regex' ' |
| 164 | test_create_repo GS-plain && |
| 165 | test_commit -C GS-plain --append A data.txt "a" && |
| 166 | test_commit -C GS-plain --append B data.txt "a a" && |
| 167 | test_commit -C GS-plain --append C data.txt "b" && |
| 168 | test_commit -C GS-plain --append D data.txt "[b]" && |
| 169 | test_commit -C GS-plain E data.txt "" && |
| 170 | |
| 171 | # We also include E, the deletion commit |
| 172 | git -C GS-plain log --grep="[ABE]" >A-to-B-then-E-log && |
| 173 | git -C GS-plain log --grep="[CDE]" >C-to-D-then-E-log && |
| 174 | git -C GS-plain log --grep="[DE]" >D-then-E-log && |
| 175 | git -C GS-plain log >full-log |
| 176 | ' |
| 177 | |
| 178 | test_expect_success 'log -G trims diff new/old [-+]' ' |
| 179 | git -C GS-plain log -G"[+-]a" >log && |
| 180 | test_must_be_empty log && |
| 181 | git -C GS-plain log -G"^a" >log && |
| 182 | test_cmp log A-to-B-then-E-log |
| 183 | ' |
| 184 | |
| 185 | test_expect_success 'log -S<pat> is not a regex, but -S<pat> --pickaxe-regex is' ' |
| 186 | git -C GS-plain log -S"a" >log && |
| 187 | test_cmp log A-to-B-then-E-log && |
| 188 | |
| 189 | git -C GS-plain log -S"[a]" >log && |
| 190 | test_must_be_empty log && |
| 191 | |
| 192 | git -C GS-plain log -S"[a]" --pickaxe-regex >log && |
| 193 | test_cmp log A-to-B-then-E-log && |
| 194 | |
| 195 | git -C GS-plain log -S"[b]" >log && |
| 196 | test_cmp log D-then-E-log && |
| 197 | |
| 198 | git -C GS-plain log -S"[b]" --pickaxe-regex >log && |
| 199 | test_cmp log C-to-D-then-E-log |
| 200 | ' |
| 201 | |
| 202 | test_expect_success 'setup log -[GS] binary & --text' ' |
| 203 | test_create_repo GS-bin-txt && |
| 204 | test_commit -C GS-bin-txt --printf A data.bin "a\na\0a\n" && |
| 205 | test_commit -C GS-bin-txt --append --printf B data.bin "a\na\0a\n" && |
| 206 | test_commit -C GS-bin-txt C data.bin "" && |
| 207 | git -C GS-bin-txt log >full-log |
| 208 | ' |
| 209 | |
| 210 | test_expect_success 'log -G ignores binary files' ' |
| 211 | git -C GS-bin-txt log -Ga >log && |
| 212 | test_must_be_empty log |
| 213 | ' |
| 214 | |
| 215 | test_expect_success 'log -G looks into binary files with -a' ' |
| 216 | git -C GS-bin-txt log -a -Ga >log && |
| 217 | test_cmp log full-log |
| 218 | ' |
| 219 | |
| 220 | test_expect_success 'log -G looks into binary files with textconv filter' ' |
| 221 | test_when_finished "rm GS-bin-txt/.gitattributes" && |
| 222 | ( |
| 223 | cd GS-bin-txt && |
| 224 | echo "* diff=bin" >.gitattributes && |
| 225 | git -c diff.bin.textconv=cat log -Ga >../log |
| 226 | ) && |
| 227 | test_cmp log full-log |
| 228 | ' |
| 229 | |
| 230 | test_expect_success 'log -S looks into binary files' ' |
| 231 | git -C GS-bin-txt log -Sa >log && |
| 232 | test_cmp log full-log |
| 233 | ' |
| 234 | |
| 235 | test_expect_success 'log -S --pickaxe-regex looks into binary files' ' |
| 236 | git -C GS-bin-txt log --pickaxe-regex -Sa >log && |
| 237 | test_cmp log full-log && |
| 238 | |
| 239 | git -C GS-bin-txt log --pickaxe-regex -S"[a]" >log && |
| 240 | test_cmp log full-log |
| 241 | ' |
| 242 | |
| 243 | test_done |