Skip to content

Commit 4d7a5ce

Browse files
committed
t5516: more tests for receive.denyCurrentBranch=updateInstead
The previous one tests only the case where a path to be updated by the push-to-deploy has an incompatible change in the target's working tree that has already been added to the index, but the feature itself wants to require the working tree to be a lot cleaner than what is tested. Add a handful more tests to protect the feature from future changes that mistakenly (from the viewpoint of the inventor of the feature) loosens the cleanliness requirement, namely: - A change only to the working tree but not to the index is still a change to be protected; - An untracked file in the working tree that would be overwritten by a push-to-deploy needs to be protected; - A change that happens to make a file identical to what is being pushed is still a change to be protected (i.e. the feature's cleanliness requirement is more strict than that of checkout). Also, test that a stat-only change to the working tree is not a reason to reject a push-to-deploy. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1404bcb commit 4d7a5ce

File tree

1 file changed

+87
-9
lines changed

1 file changed

+87
-9
lines changed

t/t5516-fetch-push.sh

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,28 +1332,106 @@ test_expect_success 'fetch into bare respects core.logallrefupdates' '
13321332

13331333
test_expect_success 'receive.denyCurrentBranch = updateInstead' '
13341334
git push testrepo master &&
1335-
(cd testrepo &&
1335+
(
1336+
cd testrepo &&
13361337
git reset --hard &&
13371338
git config receive.denyCurrentBranch updateInstead
13381339
) &&
13391340
test_commit third path2 &&
1341+
1342+
# Try pushing into a repository with pristine working tree
13401343
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 &&
13441363
git update-index -q --refresh &&
13451364
git diff-files --quiet -- &&
13461365
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)
13491369
) &&
1370+
1371+
# Update what is to be pushed
13501372
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+
) &&
13511380
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) &&
13541431
git diff --quiet &&
1355-
test changed = "$(cat path2)"
1432+
test fifth = "$(cat path3)"
13561433
)
1434+
13571435
'
13581436

13591437
test_done

0 commit comments

Comments
 (0)