1250
test_expect_code 1 grep " emp" error
1251
'
1252
1253
-test_expect_success SHA1 'short SHA-1 setup' '
1253
+test_expect_success 'short commit ID setup' '
1254
test_when_finished "git checkout master" &&
1255
git checkout --orphan collide &&
1256
git rm -rf . &&
1262
)
1263
'
1264
1265
-test_expect_success SHA1 'short SHA-1 collide' '
1265
+if test -n "$GIT_TEST_FIND_COLLIDER"
1266
+then
1267
+ author="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)"
1268
+ committer="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)"
1269
+ blob="$(git rev-parse collide2:collide)"
1270
+ from="$(git rev-parse collide1^0)"
1271
+ repl="commit refs/heads/collider-&\\n"
1272
+ repl="${repl}author $author\\ncommitter $committer\\n"
1273
+ repl="${repl}data <<EOF\\ncollide2 &\\nEOF\\n"
1274
+ repl="${repl}from $from\\nM 100644 $blob collide\\n"
1275
+ test_seq 1 32768 | sed "s|.*|$repl|" >script &&
1276
+ git fast-import <script &&
1277
+ git pack-refs &&
1278
+ git for-each-ref >refs &&
1279
+ grep "^$(test_oid t3404_collision)" <refs >matches &&
1280
+ cat matches &&
1281
+ test_line_count -gt 2 matches || {
1282
+ echo "Could not find a collider" >&2
1283
+ exit 1
1284
+ }
1285
+fi
1286
+
1287
+test_expect_success 'short commit ID collide' '
1288
+ test_oid_cache <<-EOF &&
1289
+ # collision-related constants
1290
+ t3404_collision sha1:6bcd
1291
+ t3404_collision sha256:0161
1292
+ t3404_collider sha1:ac4f2ee
1293
+ t3404_collider sha256:16697
1294
+ EOF
1295
test_when_finished "reset_rebase && git checkout master" &&
1296
git checkout collide &&
1268
- colliding_sha1=6bcda37 &&
1269
- test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" &&
1297
+ colliding_id=$(test_oid t3404_collision) &&
1298
+ hexsz=$(test_oid hexsz) &&
1299
+ test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1300
+ test_config core.abbrev 4 &&
1301
(
1302
unset test_tick &&
1303
test_tick &&
1304
set_fake_editor &&
1274
- FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1305
+ FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \
1306
FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 &&
1276
- test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" &&
1277
- grep "^pick $colliding_sha1 " \
1307
+ test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1308
+ grep "^pick $colliding_id " \
1309
.git/rebase-merge/git-rebase-todo.tmp &&
1279
- grep "^pick [0-9a-f]\{40\}" \
1310
+ grep "^pick [0-9a-f]\{$hexsz\}" \
1311
.git/rebase-merge/git-rebase-todo &&
1281
- grep "^pick [0-9a-f]\{40\}" \
1312
+ grep "^pick [0-9a-f]\{$hexsz\}" \
1313
.git/rebase-merge/git-rebase-todo.backup &&
1314
git rebase --continue
1315
) &&