1332
1333
test_expect_success 'receive.denyCurrentBranch = updateInstead' '
1334
git push testrepo master &&
1335
- (cd testrepo &&
1335
+ (
1336
+ cd testrepo &&
1337
git reset --hard &&
1338
git config receive.denyCurrentBranch updateInstead
1339
) &&
1340
test_commit third path2 &&
1341
+
1342
+ # Try pushing into a repository with pristine working tree
1343
git push testrepo master &&
1341
- test $(git rev-parse HEAD) = $(cd testrepo && git rev-parse HEAD) &&
1342
- test third = "$(cat testrepo/path2)" &&
1343
- (cd testrepo &&
1344
+ (
1345
+ cd testrepo &&
1346
+ git update-index -q --refresh &&
1347
+ git diff-files --quiet -- &&
1348
+ git diff-index --quiet --cached HEAD -- &&
1349
+ test third = "$(cat path2)" &&
1350
+ test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1351
+ ) &&
1352
+
1353
+ # Try pushing into a repository with working tree needing a refresh
1354
+ (
1355
+ cd testrepo &&
1356
+ git reset --hard HEAD^ &&
1357
+ test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1358
+ test-chmtime +100 path1
1359
+ ) &&
1360
+ git push testrepo master &&
1361
+ (
1362
+ cd testrepo &&
1363
git update-index -q --refresh &&
1364
git diff-files --quiet -- &&
1365
git diff-index --quiet --cached HEAD -- &&
1347
- echo changed >path2 &&
1348
- git add path2
1366
+ test_cmp ../path1 path1 &&
1367
+ test third = "$(cat path2)" &&
1368
+ test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD)
1369
) &&
1370
+
1371
+ # Update what is to be pushed
1372
test_commit fourth path2 &&
1373
+
1374
+ # Try pushing into a repository with a dirty working tree
1375
+ # (1) the working tree updated
1376
+ (
1377
+ cd testrepo &&
1378
+ echo changed >path1
1379
+ ) &&
1380
test_must_fail git push testrepo master &&
1352
- test $(git rev-parse HEAD^) = $(git -C testrepo rev-parse HEAD) &&
1353
- (cd testrepo &&
1381
+ (
1382
+ cd testrepo &&
1383
+ test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1384
+ git diff --quiet --cached &&
1385
+ test changed = "$(cat path1)"
1386
+ ) &&
1387
+
1388
+ # (2) the index updated
1389
+ (
1390
+ cd testrepo &&
1391
+ echo changed >path1 &&
1392
+ git add path1
1393
+ ) &&
1394
+ test_must_fail git push testrepo master &&
1395
+ (
1396
+ cd testrepo &&
1397
+ test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) &&
1398
+ git diff --quiet &&
1399
+ test changed = "$(cat path1)"
1400
+ ) &&
1401
+
1402
+ # Introduce a new file in the update
1403
+ test_commit fifth path3 &&
1404
+
1405
+ # (3) the working tree has an untracked file that would interfere
1406
+ (
1407
+ cd testrepo &&
1408
+ git reset --hard &&
1409
+ echo changed >path3
1410
+ ) &&
1411
+ test_must_fail git push testrepo master &&
1412
+ (
1413
+ cd testrepo &&
1414
+ test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1415
+ git diff --quiet &&
1416
+ git diff --quiet --cached &&
1417
+ test changed = "$(cat path3)"
1418
+ ) &&
1419
+
1420
+ # (4) the target changes to what gets pushed but it still is a change
1421
+ (
1422
+ cd testrepo &&
1423
+ git reset --hard &&
1424
+ echo fifth >path3 &&
1425
+ git add path3
1426
+ ) &&
1427
+ test_must_fail git push testrepo master &&
1428
+ (
1429
+ cd testrepo &&
1430
+ test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) &&
1431
git diff --quiet &&
1355
- test changed = "$(cat path2)"
1432
+ test fifth = "$(cat path3)"
1433
)
1434
+
1435
'
1436
1437
test_done