This adds tests for the atomic push option. The first four tests check if the atomic option works in good conditions and the last three patches check if the atomic option prevents any change to be pushed if just one ref cannot be updated. Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> --- Notes: Originally Ronnie had a similar patch prepared. But as I added more tests and cleaned up the existing tests (e.g. use test_commit instead of "echo one >file && gitadd file && git commit -a -m 'one'", removal of dead code), the file has changed so much that I'd rather take ownership. t/t5543-atomic-push.sh | 185 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100755 t/t5543-atomic-push.sh diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh new file mode 100755 index 0000000..6cbedc5 --- /dev/null +++ b/t/t5543-atomic-push.sh @@ -0,0 +1,185 @@ +#!/bin/sh + +test_description='pushing to a repository using the atomic push option' + +. ./test-lib.sh + +D=`pwd` + +mk_repo_pair () { + rm -rf workbench upstream thirdparty && + mkdir upstream && + ( + cd upstream && + git init --bare #&& + #git config receive.denyCurrentBranch warn + ) && + mkdir workbench && + ( + cd workbench && + git init && + git remote add up ../upstream + ) +} + +test_push_failed () { + workbench_master=$(cd workbench && git show-ref -s --verify refs/heads/master) && + upstream_master=$(cd upstream && git show-ref -s --verify refs/heads/master) && + test "$workbench_master" != "$upstream_master" && + + workbench_second=$(cd workbench && git show-ref -s --verify refs/heads/second) && + upstream_second=$(cd upstream && git show-ref -s --verify refs/heads/second) && + test "$workbench_second" != "$upstream_second" +} + +test_push_succeeded () { + workbench_master=$(cd workbench && git show-ref -s --verify refs/heads/master) && + upstream_master=$(cd upstream && git show-ref -s --verify refs/heads/master) && + test "$workbench_master" = "$upstream_master" + + workbench_second=$(cd workbench && git show-ref -s --verify refs/heads/second) && + upstream_second=$(cd upstream && git show-ref -s --verify refs/heads/second) && + test "$workbench_second" = "$upstream_second" +} + +test_expect_success 'atomic push works for a single branch' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git push --mirror up && + test_commit two && + git push --atomic-push --mirror up + ) && + workbench_master=$(cd workbench && git show-ref -s --verify refs/heads/master) && + upstream_master=$(cd upstream && git show-ref -s --verify refs/heads/master) && + test "$workbench_master" = "$upstream_master" +' + +test_expect_success 'atomic push works for two branches' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git branch second && + git push --mirror up && + test_commit two && + git checkout second && + test_commit three && + git push --atomic-push --mirror up + ) && + test_push_succeeded +' + +test_expect_success 'atomic push works in combination with --mirror' ' + mk_repo_pair && + ls workbench && + ( + cd workbench && + test_commit one && + git checkout -b second && + test_commit two && + git push --atomic-push --mirror up + ) && + test_push_succeeded +' + +test_expect_success 'atomic push works in combination with --force' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git checkout -b second && + test_commit two && + test_commit three && + test_commit four && + git push --mirror up && + git reset --hard HEAD^ && + git push --force --atomic-push up master second + ) && + test_push_succeeded +' + +# set up two branches where master can be pushed but second can not +# (non-fast-forward). Since second can not be pushed the whole operation +# will fail and leave master untouched. +test_expect_success 'atomic push fails if one branch fails locally' ' + mk_repo_pair && + ( + cd workbench && + test_commit one && + git checkout -b second master && + test_commit two && + test_commit three && + test_commit four && + git push --mirror up + git reset --hard HEAD~2 && + git checkout master && + test_commit five && + ! git push --atomic-push --all up + ) && + test_push_failed +' + +test_expect_success 'atomic push fails if one branch fails remotely' ' + # prepare the repo + mk_repo_pair && + ( + cd workbench && + test_commit one && + git checkout -b second master && + test_commit two && + git push --mirror up + ) && + # a third party modifies the server side: + ( + git clone upstream thirdparty && + cd thirdparty + git checkout second + test_commit unrelated_changes && + git push origin second + ) && + # see if we can now push both branches. + ( + cd workbench && + git checkout master && + test_commit three && + git checkout second && + test_commit four && + ! git push --atomic-push up master second + ) && + test_push_failed +' + +test_expect_success 'atomic push fails if one tag fails remotely' ' + # prepare the repo + mk_repo_pair && + ( + cd workbench && + test_commit one && + git checkout -b second master && + test_commit two && + git push --mirror up + ) && + # a third party modifies the server side: + ( + git clone upstream thirdparty && + cd thirdparty + git checkout second + git tag test_tag && + git push --tags origin second + ) && + # see if we can now push both branches. + ( + cd workbench && + git checkout master && + test_commit three && + git checkout second && + test_commit four && + git tag test_tag && + ! git push --tags --atomic-push up master second + ) && + test_push_failed +' + +test_done -- 2.2.0.33.gc2219e3.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html