| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='push to remote group' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=default |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'setup' ' |
| 11 | for i in 1 2 3 |
| 12 | do |
| 13 | git init --bare dest-$i.git && |
| 14 | git -C dest-$i.git symbolic-ref HEAD refs/heads/not-a-branch || |
| 15 | return 1 |
| 16 | done && |
| 17 | test_tick && |
| 18 | git commit --allow-empty -m "initial" && |
| 19 | git config set remote.remote-1.url "file://$(pwd)/dest-1.git" && |
| 20 | git config set remote.remote-1.fetch "+refs/heads/*:refs/remotes/remote-1/*" && |
| 21 | git config set remote.remote-2.url "file://$(pwd)/dest-2.git" && |
| 22 | git config set remote.remote-2.fetch "+refs/heads/*:refs/remotes/remote-2/*" && |
| 23 | git config set remote.remote-3.url "file://$(pwd)/dest-3.git" && |
| 24 | git config set remote.remote-3.fetch "+refs/heads/*:refs/remotes/remote-3/*" && |
| 25 | git config set remotes.all-remotes "remote-1 remote-2 remote-3" |
| 26 | ' |
| 27 | |
| 28 | test_expect_success 'push to remote group updates all members correctly' ' |
| 29 | git push all-remotes HEAD:refs/heads/main && |
| 30 | git rev-parse HEAD >expect && |
| 31 | for i in 1 2 3 |
| 32 | do |
| 33 | git -C dest-$i.git rev-parse refs/heads/main >actual || |
| 34 | return 1 |
| 35 | test_cmp expect actual || return 1 |
| 36 | done |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'push second commit to group updates all members' ' |
| 40 | test_tick && |
| 41 | git commit --allow-empty -m "second" && |
| 42 | git push all-remotes HEAD:refs/heads/main && |
| 43 | git rev-parse HEAD >expect && |
| 44 | for i in 1 2 3 |
| 45 | do |
| 46 | git -C dest-$i.git rev-parse refs/heads/main >actual || |
| 47 | return 1 |
| 48 | test_cmp expect actual || return 1 |
| 49 | done |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'push to single remote in group does not affect others' ' |
| 53 | test_tick && |
| 54 | git commit --allow-empty -m "third" && |
| 55 | git push remote-1 HEAD:refs/heads/main && |
| 56 | git -C dest-1.git rev-parse refs/heads/main >hash-after-1 && |
| 57 | git -C dest-2.git rev-parse refs/heads/main >hash-after-2 && |
| 58 | ! test_cmp hash-after-1 hash-after-2 |
| 59 | ' |
| 60 | |
| 61 | test_expect_success 'mirror remote in group with refspec fails' ' |
| 62 | git config set remote.remote-1.mirror true && |
| 63 | test_must_fail git push all-remotes HEAD:refs/heads/main 2>err && |
| 64 | test_grep "mirror" err && |
| 65 | git config unset remote.remote-1.mirror |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'push.default=current works with group push' ' |
| 69 | git config set push.default current && |
| 70 | test_tick && |
| 71 | git commit --allow-empty -m "fifth" && |
| 72 | git push all-remotes && |
| 73 | git config unset push.default |
| 74 | ' |
| 75 | |
| 76 | test_expect_success '--atomic is rejected for group push' ' |
| 77 | test_must_fail git push --atomic all-remotes HEAD:refs/heads/main 2>err && |
| 78 | test_grep "atomic" err |
| 79 | ' |
| 80 | |
| 81 | test_expect_success 'push continues past rejection to remaining remotes' ' |
| 82 | for i in c1 c2 c3 |
| 83 | do |
| 84 | git init --bare dest-$i.git || return 1 |
| 85 | done && |
| 86 | git config set remote.c1.url "file://$(pwd)/dest-c1.git" && |
| 87 | git config set remote.c2.url "file://$(pwd)/dest-c2.git" && |
| 88 | git config set remote.c3.url "file://$(pwd)/dest-c3.git" && |
| 89 | git config set remotes.continue-group "c1 c2 c3" && |
| 90 | |
| 91 | test_tick && |
| 92 | git commit --allow-empty -m "base for continue test" && |
| 93 | |
| 94 | # initial sync |
| 95 | git push continue-group HEAD:refs/heads/main && |
| 96 | |
| 97 | # advance c2 independently |
| 98 | git clone dest-c2.git tmp-c2 && |
| 99 | ( |
| 100 | cd tmp-c2 && |
| 101 | git checkout -b main origin/main && |
| 102 | test_commit c2_independent && |
| 103 | git push origin HEAD:refs/heads/main |
| 104 | ) && |
| 105 | rm -rf tmp-c2 && |
| 106 | |
| 107 | test_tick && |
| 108 | git commit --allow-empty -m "local diverging commit" && |
| 109 | |
| 110 | # push: c2 rejects, others succeed |
| 111 | test_must_fail git push continue-group HEAD:refs/heads/main && |
| 112 | |
| 113 | git rev-parse HEAD >expect && |
| 114 | git -C dest-c1.git rev-parse refs/heads/main >actual-c1 && |
| 115 | git -C dest-c3.git rev-parse refs/heads/main >actual-c3 && |
| 116 | test_cmp expect actual-c1 && |
| 117 | test_cmp expect actual-c3 && |
| 118 | |
| 119 | # c2 should not have the new commit |
| 120 | git -C dest-c2.git rev-parse refs/heads/main >actual-c2 && |
| 121 | ! test_cmp expect actual-c2 |
| 122 | ' |
| 123 | |
| 124 | test_expect_success 'fatal connection error does not stop remaining remotes' ' |
| 125 | for i in f1 f2 f3 |
| 126 | do |
| 127 | git init --bare dest-$i.git || return 1 |
| 128 | done && |
| 129 | git config set remote.f1.url "file://$(pwd)/dest-f1.git" && |
| 130 | git config set remote.f2.url "file://$(pwd)/dest-f2.git" && |
| 131 | git config set remote.f3.url "file://$(pwd)/dest-f3.git" && |
| 132 | git config set remotes.fatal-group "f1 f2 f3" && |
| 133 | |
| 134 | test_tick && |
| 135 | git commit --allow-empty -m "base for fatal test" && |
| 136 | |
| 137 | # initial sync |
| 138 | git push fatal-group HEAD:refs/heads/main && |
| 139 | |
| 140 | # break f2 |
| 141 | git config set remote.f2.url "file:///tmp/does-not-exist-$$" && |
| 142 | |
| 143 | test_tick && |
| 144 | git commit --allow-empty -m "after fatal setup" && |
| 145 | |
| 146 | # overall exit code is non-zero because f2 failed |
| 147 | test_must_fail git push fatal-group HEAD:refs/heads/main && |
| 148 | |
| 149 | git rev-parse HEAD >expect && |
| 150 | |
| 151 | # f1 and f3 should both have the new commit — subprocesses are independent |
| 152 | git -C dest-f1.git rev-parse refs/heads/main >actual-f1 && |
| 153 | test_cmp expect actual-f1 && |
| 154 | git -C dest-f3.git rev-parse refs/heads/main >actual-f3 && |
| 155 | test_cmp expect actual-f3 && |
| 156 | |
| 157 | git config set remote.f2.url "file://$(pwd)/dest-f2.git" |
| 158 | ' |
| 159 | |
| 160 | test_done |