Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test grep recurse-submodules feature |
| 4 | |
| 5 | This test verifies the recurse-submodules feature correctly greps across |
| 6 | submodules. |
| 7 | ' |
| 8 | |
| 9 | . ./test-lib.sh |
| 10 | |
| 11 | test_expect_success 'setup directory structure and submodule' ' |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 12 | echo "(1|2)d(3|4)" >a && |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 13 | mkdir b && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 14 | echo "(3|4)" >b/b && |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 15 | git add a b && |
| 16 | git commit -m "add a and b" && |
| 17 | git init submodule && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 18 | echo "(1|2)d(3|4)" >submodule/a && |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 19 | git -C submodule add a && |
| 20 | git -C submodule commit -m "add a" && |
| 21 | git submodule add ./submodule && |
| 22 | git commit -m "added submodule" |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'grep correctly finds patterns in a submodule' ' |
| 26 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 27 | a:(1|2)d(3|4) |
| 28 | b/b:(3|4) |
| 29 | submodule/a:(1|2)d(3|4) |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 30 | EOF |
| 31 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 32 | git grep -e "(3|4)" --recurse-submodules >actual && |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 33 | test_cmp expect actual |
| 34 | ' |
| 35 | |
Stefan Beller | 9071c07 | 2017-05-31 17:30:48 -0700 | [diff] [blame] | 36 | test_expect_success 'grep finds patterns in a submodule via config' ' |
| 37 | test_config submodule.recurse true && |
| 38 | # expect from previous test |
| 39 | git grep -e "(3|4)" >actual && |
| 40 | test_cmp expect actual |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'grep --no-recurse-submodules overrides config' ' |
| 44 | test_config submodule.recurse true && |
| 45 | cat >expect <<-\EOF && |
| 46 | a:(1|2)d(3|4) |
| 47 | b/b:(3|4) |
| 48 | EOF |
| 49 | |
| 50 | git grep -e "(3|4)" --no-recurse-submodules >actual && |
| 51 | test_cmp expect actual |
| 52 | ' |
| 53 | |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 54 | test_expect_success 'grep and basic pathspecs' ' |
| 55 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 56 | submodule/a:(1|2)d(3|4) |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 57 | EOF |
| 58 | |
| 59 | git grep -e. --recurse-submodules -- submodule >actual && |
| 60 | test_cmp expect actual |
| 61 | ' |
| 62 | |
| 63 | test_expect_success 'grep and nested submodules' ' |
| 64 | git init submodule/sub && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 65 | echo "(1|2)d(3|4)" >submodule/sub/a && |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 66 | git -C submodule/sub add a && |
| 67 | git -C submodule/sub commit -m "add a" && |
| 68 | git -C submodule submodule add ./sub && |
| 69 | git -C submodule add sub && |
| 70 | git -C submodule commit -m "added sub" && |
| 71 | git add submodule && |
| 72 | git commit -m "updated submodule" && |
| 73 | |
| 74 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 75 | a:(1|2)d(3|4) |
| 76 | b/b:(3|4) |
| 77 | submodule/a:(1|2)d(3|4) |
| 78 | submodule/sub/a:(1|2)d(3|4) |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 79 | EOF |
| 80 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 81 | git grep -e "(3|4)" --recurse-submodules >actual && |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 82 | test_cmp expect actual |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'grep and multiple patterns' ' |
| 86 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 87 | a:(1|2)d(3|4) |
| 88 | submodule/a:(1|2)d(3|4) |
| 89 | submodule/sub/a:(1|2)d(3|4) |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 90 | EOF |
| 91 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 92 | git grep -e "(3|4)" --and -e "(1|2)" --recurse-submodules >actual && |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 93 | test_cmp expect actual |
| 94 | ' |
| 95 | |
| 96 | test_expect_success 'grep and multiple patterns' ' |
| 97 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 98 | b/b:(3|4) |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 99 | EOF |
| 100 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 101 | git grep -e "(3|4)" --and --not -e "(1|2)" --recurse-submodules >actual && |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 102 | test_cmp expect actual |
| 103 | ' |
| 104 | |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 105 | test_expect_success 'basic grep tree' ' |
| 106 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 107 | HEAD:a:(1|2)d(3|4) |
| 108 | HEAD:b/b:(3|4) |
| 109 | HEAD:submodule/a:(1|2)d(3|4) |
| 110 | HEAD:submodule/sub/a:(1|2)d(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 111 | EOF |
| 112 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 113 | git grep -e "(3|4)" --recurse-submodules HEAD >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 114 | test_cmp expect actual |
| 115 | ' |
| 116 | |
| 117 | test_expect_success 'grep tree HEAD^' ' |
| 118 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 119 | HEAD^:a:(1|2)d(3|4) |
| 120 | HEAD^:b/b:(3|4) |
| 121 | HEAD^:submodule/a:(1|2)d(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 122 | EOF |
| 123 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 124 | git grep -e "(3|4)" --recurse-submodules HEAD^ >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 125 | test_cmp expect actual |
| 126 | ' |
| 127 | |
| 128 | test_expect_success 'grep tree HEAD^^' ' |
| 129 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 130 | HEAD^^:a:(1|2)d(3|4) |
| 131 | HEAD^^:b/b:(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 132 | EOF |
| 133 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 134 | git grep -e "(3|4)" --recurse-submodules HEAD^^ >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 135 | test_cmp expect actual |
| 136 | ' |
| 137 | |
| 138 | test_expect_success 'grep tree and pathspecs' ' |
| 139 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 140 | HEAD:submodule/a:(1|2)d(3|4) |
| 141 | HEAD:submodule/sub/a:(1|2)d(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 142 | EOF |
| 143 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 144 | git grep -e "(3|4)" --recurse-submodules HEAD -- submodule >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 145 | test_cmp expect actual |
| 146 | ' |
| 147 | |
| 148 | test_expect_success 'grep tree and pathspecs' ' |
| 149 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 150 | HEAD:submodule/a:(1|2)d(3|4) |
| 151 | HEAD:submodule/sub/a:(1|2)d(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 152 | EOF |
| 153 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 154 | git grep -e "(3|4)" --recurse-submodules HEAD -- "submodule*a" >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 155 | test_cmp expect actual |
| 156 | ' |
| 157 | |
| 158 | test_expect_success 'grep tree and more pathspecs' ' |
| 159 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 160 | HEAD:submodule/a:(1|2)d(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 161 | EOF |
| 162 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 163 | git grep -e "(3|4)" --recurse-submodules HEAD -- "submodul?/a" >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 164 | test_cmp expect actual |
| 165 | ' |
| 166 | |
| 167 | test_expect_success 'grep tree and more pathspecs' ' |
| 168 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 169 | HEAD:submodule/sub/a:(1|2)d(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 170 | EOF |
| 171 | |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 172 | git grep -e "(3|4)" --recurse-submodules HEAD -- "submodul*/sub/a" >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 173 | test_cmp expect actual |
| 174 | ' |
| 175 | |
| 176 | test_expect_success !MINGW 'grep recurse submodule colon in name' ' |
| 177 | git init parent && |
| 178 | test_when_finished "rm -rf parent" && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 179 | echo "(1|2)d(3|4)" >"parent/fi:le" && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 180 | git -C parent add "fi:le" && |
| 181 | git -C parent commit -m "add fi:le" && |
| 182 | |
| 183 | git init "su:b" && |
| 184 | test_when_finished "rm -rf su:b" && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 185 | echo "(1|2)d(3|4)" >"su:b/fi:le" && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 186 | git -C "su:b" add "fi:le" && |
| 187 | git -C "su:b" commit -m "add fi:le" && |
| 188 | |
| 189 | git -C parent submodule add "../su:b" "su:b" && |
| 190 | git -C parent commit -m "add submodule" && |
| 191 | |
| 192 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 193 | fi:le:(1|2)d(3|4) |
| 194 | su:b/fi:le:(1|2)d(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 195 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 196 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 197 | test_cmp expect actual && |
| 198 | |
| 199 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 200 | HEAD:fi:le:(1|2)d(3|4) |
| 201 | HEAD:su:b/fi:le:(1|2)d(3|4) |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 202 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 203 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules HEAD >actual && |
Brandon Williams | 74ed437 | 2016-12-16 11:03:21 -0800 | [diff] [blame] | 204 | test_cmp expect actual |
| 205 | ' |
| 206 | |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 207 | test_expect_success 'grep history with moved submoules' ' |
| 208 | git init parent && |
| 209 | test_when_finished "rm -rf parent" && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 210 | echo "(1|2)d(3|4)" >parent/file && |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 211 | git -C parent add file && |
| 212 | git -C parent commit -m "add file" && |
| 213 | |
| 214 | git init sub && |
| 215 | test_when_finished "rm -rf sub" && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 216 | echo "(1|2)d(3|4)" >sub/file && |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 217 | git -C sub add file && |
| 218 | git -C sub commit -m "add file" && |
| 219 | |
| 220 | git -C parent submodule add ../sub dir/sub && |
| 221 | git -C parent commit -m "add submodule" && |
| 222 | |
| 223 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 224 | dir/sub/file:(1|2)d(3|4) |
| 225 | file:(1|2)d(3|4) |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 226 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 227 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules >actual && |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 228 | test_cmp expect actual && |
| 229 | |
| 230 | git -C parent mv dir/sub sub-moved && |
| 231 | git -C parent commit -m "moved submodule" && |
| 232 | |
| 233 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 234 | file:(1|2)d(3|4) |
| 235 | sub-moved/file:(1|2)d(3|4) |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 236 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 237 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules >actual && |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 238 | test_cmp expect actual && |
| 239 | |
| 240 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 241 | HEAD^:dir/sub/file:(1|2)d(3|4) |
| 242 | HEAD^:file:(1|2)d(3|4) |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 243 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 244 | git -C parent grep -e "(1|2)d(3|4)" --recurse-submodules HEAD^ >actual && |
Brandon Williams | e6fac7f | 2016-12-16 11:03:22 -0800 | [diff] [blame] | 245 | test_cmp expect actual |
| 246 | ' |
| 247 | |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 248 | test_expect_success 'grep using relative path' ' |
| 249 | test_when_finished "rm -rf parent sub" && |
| 250 | git init sub && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 251 | echo "(1|2)d(3|4)" >sub/file && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 252 | git -C sub add file && |
| 253 | git -C sub commit -m "add file" && |
| 254 | |
| 255 | git init parent && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 256 | echo "(1|2)d(3|4)" >parent/file && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 257 | git -C parent add file && |
| 258 | mkdir parent/src && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 259 | echo "(1|2)d(3|4)" >parent/src/file2 && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 260 | git -C parent add src/file2 && |
| 261 | git -C parent submodule add ../sub && |
| 262 | git -C parent commit -m "add files and submodule" && |
| 263 | |
| 264 | # From top works |
| 265 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 266 | file:(1|2)d(3|4) |
| 267 | src/file2:(1|2)d(3|4) |
| 268 | sub/file:(1|2)d(3|4) |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 269 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 270 | git -C parent grep --recurse-submodules -e "(1|2)d(3|4)" >actual && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 271 | test_cmp expect actual && |
| 272 | |
| 273 | # Relative path to top |
| 274 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 275 | ../file:(1|2)d(3|4) |
| 276 | file2:(1|2)d(3|4) |
| 277 | ../sub/file:(1|2)d(3|4) |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 278 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 279 | git -C parent/src grep --recurse-submodules -e "(1|2)d(3|4)" -- .. >actual && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 280 | test_cmp expect actual && |
| 281 | |
| 282 | # Relative path to submodule |
| 283 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 284 | ../sub/file:(1|2)d(3|4) |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 285 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 286 | git -C parent/src grep --recurse-submodules -e "(1|2)d(3|4)" -- ../sub >actual && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 287 | test_cmp expect actual |
| 288 | ' |
| 289 | |
| 290 | test_expect_success 'grep from a subdir' ' |
| 291 | test_when_finished "rm -rf parent sub" && |
| 292 | git init sub && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 293 | echo "(1|2)d(3|4)" >sub/file && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 294 | git -C sub add file && |
| 295 | git -C sub commit -m "add file" && |
| 296 | |
| 297 | git init parent && |
| 298 | mkdir parent/src && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 299 | echo "(1|2)d(3|4)" >parent/src/file && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 300 | git -C parent add src/file && |
| 301 | git -C parent submodule add ../sub src/sub && |
| 302 | git -C parent submodule add ../sub sub && |
| 303 | git -C parent commit -m "add files and submodules" && |
| 304 | |
| 305 | # Verify grep from root works |
| 306 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 307 | src/file:(1|2)d(3|4) |
| 308 | src/sub/file:(1|2)d(3|4) |
| 309 | sub/file:(1|2)d(3|4) |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 310 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 311 | git -C parent grep --recurse-submodules -e "(1|2)d(3|4)" >actual && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 312 | test_cmp expect actual && |
| 313 | |
| 314 | # Verify grep from a subdir works |
| 315 | cat >expect <<-\EOF && |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 316 | file:(1|2)d(3|4) |
| 317 | sub/file:(1|2)d(3|4) |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 318 | EOF |
Ævar Arnfjörð Bjarmason | 5d52a30 | 2017-05-20 21:42:13 +0000 | [diff] [blame] | 319 | git -C parent/src grep --recurse-submodules -e "(1|2)d(3|4)" >actual && |
Brandon Williams | be80a23 | 2017-03-17 10:22:55 -0700 | [diff] [blame] | 320 | test_cmp expect actual |
| 321 | ' |
| 322 | |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 323 | test_incompatible_with_recurse_submodules () |
| 324 | { |
| 325 | test_expect_success "--recurse-submodules and $1 are incompatible" " |
| 326 | test_must_fail git grep -e. --recurse-submodules $1 2>actual && |
| 327 | test_i18ngrep 'not supported with --recurse-submodules' actual |
| 328 | " |
| 329 | } |
| 330 | |
| 331 | test_incompatible_with_recurse_submodules --untracked |
| 332 | test_incompatible_with_recurse_submodules --no-index |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 333 | |
Ævar Arnfjörð Bjarmason | 5ee6f1a | 2017-05-20 21:42:14 +0000 | [diff] [blame] | 334 | test_expect_success 'grep --recurse-submodules should pass the pattern type along' ' |
| 335 | # Fixed |
| 336 | test_must_fail git grep -F --recurse-submodules -e "(.|.)[\d]" && |
| 337 | test_must_fail git -c grep.patternType=fixed grep --recurse-submodules -e "(.|.)[\d]" && |
| 338 | |
| 339 | # Basic |
| 340 | git grep -G --recurse-submodules -e "(.|.)[\d]" >actual && |
| 341 | cat >expect <<-\EOF && |
| 342 | a:(1|2)d(3|4) |
| 343 | submodule/a:(1|2)d(3|4) |
| 344 | submodule/sub/a:(1|2)d(3|4) |
| 345 | EOF |
| 346 | test_cmp expect actual && |
| 347 | git -c grep.patternType=basic grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 348 | test_cmp expect actual && |
| 349 | |
| 350 | # Extended |
| 351 | git grep -E --recurse-submodules -e "(.|.)[\d]" >actual && |
| 352 | cat >expect <<-\EOF && |
| 353 | .gitmodules:[submodule "submodule"] |
| 354 | .gitmodules: path = submodule |
| 355 | .gitmodules: url = ./submodule |
| 356 | a:(1|2)d(3|4) |
| 357 | submodule/.gitmodules:[submodule "sub"] |
| 358 | submodule/a:(1|2)d(3|4) |
| 359 | submodule/sub/a:(1|2)d(3|4) |
| 360 | EOF |
| 361 | test_cmp expect actual && |
| 362 | git -c grep.patternType=extended grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 363 | test_cmp expect actual && |
| 364 | git -c grep.extendedRegexp=true grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 365 | test_cmp expect actual && |
| 366 | |
| 367 | # Perl |
| 368 | if test_have_prereq PCRE |
| 369 | then |
| 370 | git grep -P --recurse-submodules -e "(.|.)[\d]" >actual && |
| 371 | cat >expect <<-\EOF && |
| 372 | a:(1|2)d(3|4) |
| 373 | b/b:(3|4) |
| 374 | submodule/a:(1|2)d(3|4) |
| 375 | submodule/sub/a:(1|2)d(3|4) |
| 376 | EOF |
| 377 | test_cmp expect actual && |
| 378 | git -c grep.patternType=perl grep --recurse-submodules -e "(.|.)[\d]" >actual && |
| 379 | test_cmp expect actual |
| 380 | fi |
| 381 | ' |
| 382 | |
Brandon Williams | 0281e48 | 2016-12-16 11:03:20 -0800 | [diff] [blame] | 383 | test_done |