| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='pushing to a mirror repository' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | D=$(pwd) |
| 11 | |
| 12 | invert () { |
| 13 | if "$@"; then |
| 14 | return 1 |
| 15 | else |
| 16 | return 0 |
| 17 | fi |
| 18 | } |
| 19 | |
| 20 | mk_repo_pair () { |
| 21 | rm -rf main mirror && |
| 22 | mkdir mirror && |
| 23 | ( |
| 24 | cd mirror && |
| 25 | git init && |
| 26 | git config receive.denyCurrentBranch warn |
| 27 | ) && |
| 28 | mkdir main && |
| 29 | ( |
| 30 | cd main && |
| 31 | git init && |
| 32 | git remote add $1 up ../mirror |
| 33 | ) |
| 34 | } |
| 35 | |
| 36 | |
| 37 | # BRANCH tests |
| 38 | test_expect_success 'push mirror creates new branches' ' |
| 39 | |
| 40 | mk_repo_pair && |
| 41 | ( |
| 42 | cd main && |
| 43 | echo one >foo && git add foo && git commit -m one && |
| 44 | git push --mirror up |
| 45 | ) && |
| 46 | main_main=$(cd main && git show-ref -s --verify refs/heads/main) && |
| 47 | mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) && |
| 48 | test "$main_main" = "$mirror_main" |
| 49 | |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'push mirror updates existing branches' ' |
| 53 | |
| 54 | mk_repo_pair && |
| 55 | ( |
| 56 | cd main && |
| 57 | echo one >foo && git add foo && git commit -m one && |
| 58 | git push --mirror up && |
| 59 | echo two >foo && git add foo && git commit -m two && |
| 60 | git push --mirror up |
| 61 | ) && |
| 62 | main_main=$(cd main && git show-ref -s --verify refs/heads/main) && |
| 63 | mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) && |
| 64 | test "$main_main" = "$mirror_main" |
| 65 | |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'push mirror force updates existing branches' ' |
| 69 | |
| 70 | mk_repo_pair && |
| 71 | ( |
| 72 | cd main && |
| 73 | echo one >foo && git add foo && git commit -m one && |
| 74 | git push --mirror up && |
| 75 | echo two >foo && git add foo && git commit -m two && |
| 76 | git push --mirror up && |
| 77 | git reset --hard HEAD^ && |
| 78 | git push --mirror up |
| 79 | ) && |
| 80 | main_main=$(cd main && git show-ref -s --verify refs/heads/main) && |
| 81 | mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) && |
| 82 | test "$main_main" = "$mirror_main" |
| 83 | |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'push mirror removes branches' ' |
| 87 | |
| 88 | mk_repo_pair && |
| 89 | ( |
| 90 | cd main && |
| 91 | echo one >foo && git add foo && git commit -m one && |
| 92 | git branch remove main && |
| 93 | git push --mirror up && |
| 94 | git branch -D remove && |
| 95 | git push --mirror up |
| 96 | ) && |
| 97 | ( |
| 98 | cd mirror && |
| 99 | invert git show-ref -s --verify refs/heads/remove |
| 100 | ) |
| 101 | |
| 102 | ' |
| 103 | |
| 104 | test_expect_success 'push mirror adds, updates and removes branches together' ' |
| 105 | |
| 106 | mk_repo_pair && |
| 107 | ( |
| 108 | cd main && |
| 109 | echo one >foo && git add foo && git commit -m one && |
| 110 | git branch remove main && |
| 111 | git push --mirror up && |
| 112 | git branch -D remove && |
| 113 | git branch add main && |
| 114 | echo two >foo && git add foo && git commit -m two && |
| 115 | git push --mirror up |
| 116 | ) && |
| 117 | main_main=$(cd main && git show-ref -s --verify refs/heads/main) && |
| 118 | main_add=$(cd main && git show-ref -s --verify refs/heads/add) && |
| 119 | mirror_main=$(cd mirror && git show-ref -s --verify refs/heads/main) && |
| 120 | mirror_add=$(cd mirror && git show-ref -s --verify refs/heads/add) && |
| 121 | test "$main_main" = "$mirror_main" && |
| 122 | test "$main_add" = "$mirror_add" && |
| 123 | ( |
| 124 | cd mirror && |
| 125 | invert git show-ref -s --verify refs/heads/remove |
| 126 | ) |
| 127 | |
| 128 | ' |
| 129 | |
| 130 | |
| 131 | # TAG tests |
| 132 | test_expect_success 'push mirror creates new tags' ' |
| 133 | |
| 134 | mk_repo_pair && |
| 135 | ( |
| 136 | cd main && |
| 137 | echo one >foo && git add foo && git commit -m one && |
| 138 | git tag -f tmain main && |
| 139 | git push --mirror up |
| 140 | ) && |
| 141 | main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) && |
| 142 | mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) && |
| 143 | test "$main_main" = "$mirror_main" |
| 144 | |
| 145 | ' |
| 146 | |
| 147 | test_expect_success 'push mirror updates existing tags' ' |
| 148 | |
| 149 | mk_repo_pair && |
| 150 | ( |
| 151 | cd main && |
| 152 | echo one >foo && git add foo && git commit -m one && |
| 153 | git tag -f tmain main && |
| 154 | git push --mirror up && |
| 155 | echo two >foo && git add foo && git commit -m two && |
| 156 | git tag -f tmain main && |
| 157 | git push --mirror up |
| 158 | ) && |
| 159 | main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) && |
| 160 | mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) && |
| 161 | test "$main_main" = "$mirror_main" |
| 162 | |
| 163 | ' |
| 164 | |
| 165 | test_expect_success 'push mirror force updates existing tags' ' |
| 166 | |
| 167 | mk_repo_pair && |
| 168 | ( |
| 169 | cd main && |
| 170 | echo one >foo && git add foo && git commit -m one && |
| 171 | git tag -f tmain main && |
| 172 | git push --mirror up && |
| 173 | echo two >foo && git add foo && git commit -m two && |
| 174 | git tag -f tmain main && |
| 175 | git push --mirror up && |
| 176 | git reset --hard HEAD^ && |
| 177 | git tag -f tmain main && |
| 178 | git push --mirror up |
| 179 | ) && |
| 180 | main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) && |
| 181 | mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) && |
| 182 | test "$main_main" = "$mirror_main" |
| 183 | |
| 184 | ' |
| 185 | |
| 186 | test_expect_success 'push mirror removes tags' ' |
| 187 | |
| 188 | mk_repo_pair && |
| 189 | ( |
| 190 | cd main && |
| 191 | echo one >foo && git add foo && git commit -m one && |
| 192 | git tag -f tremove main && |
| 193 | git push --mirror up && |
| 194 | git tag -d tremove && |
| 195 | git push --mirror up |
| 196 | ) && |
| 197 | ( |
| 198 | cd mirror && |
| 199 | invert git show-ref -s --verify refs/tags/tremove |
| 200 | ) |
| 201 | |
| 202 | ' |
| 203 | |
| 204 | test_expect_success 'push mirror adds, updates and removes tags together' ' |
| 205 | |
| 206 | mk_repo_pair && |
| 207 | ( |
| 208 | cd main && |
| 209 | echo one >foo && git add foo && git commit -m one && |
| 210 | git tag -f tmain main && |
| 211 | git tag -f tremove main && |
| 212 | git push --mirror up && |
| 213 | git tag -d tremove && |
| 214 | git tag tadd main && |
| 215 | echo two >foo && git add foo && git commit -m two && |
| 216 | git tag -f tmain main && |
| 217 | git push --mirror up |
| 218 | ) && |
| 219 | main_main=$(cd main && git show-ref -s --verify refs/tags/tmain) && |
| 220 | main_add=$(cd main && git show-ref -s --verify refs/tags/tadd) && |
| 221 | mirror_main=$(cd mirror && git show-ref -s --verify refs/tags/tmain) && |
| 222 | mirror_add=$(cd mirror && git show-ref -s --verify refs/tags/tadd) && |
| 223 | test "$main_main" = "$mirror_main" && |
| 224 | test "$main_add" = "$mirror_add" && |
| 225 | ( |
| 226 | cd mirror && |
| 227 | invert git show-ref -s --verify refs/tags/tremove |
| 228 | ) |
| 229 | |
| 230 | ' |
| 231 | |
| 232 | test_expect_success 'remote.foo.mirror adds and removes branches' ' |
| 233 | |
| 234 | mk_repo_pair --mirror && |
| 235 | ( |
| 236 | cd main && |
| 237 | echo one >foo && git add foo && git commit -m one && |
| 238 | git branch keep main && |
| 239 | git branch remove main && |
| 240 | git push up && |
| 241 | git branch -D remove && |
| 242 | git push up |
| 243 | ) && |
| 244 | ( |
| 245 | cd mirror && |
| 246 | git show-ref -s --verify refs/heads/keep && |
| 247 | invert git show-ref -s --verify refs/heads/remove |
| 248 | ) |
| 249 | |
| 250 | ' |
| 251 | |
| 252 | test_expect_success 'remote.foo.mirror=no has no effect' ' |
| 253 | |
| 254 | mk_repo_pair && |
| 255 | ( |
| 256 | cd main && |
| 257 | echo one >foo && git add foo && git commit -m one && |
| 258 | git config --add remote.up.mirror no && |
| 259 | git branch keep main && |
| 260 | git push --mirror up && |
| 261 | git branch -D keep && |
| 262 | git push up : |
| 263 | ) && |
| 264 | ( |
| 265 | cd mirror && |
| 266 | git show-ref -s --verify refs/heads/keep |
| 267 | ) |
| 268 | |
| 269 | ' |
| 270 | |
| 271 | test_expect_success 'push to mirrored repository with refspec fails' ' |
| 272 | mk_repo_pair && |
| 273 | ( |
| 274 | cd main && |
| 275 | echo one >foo && git add foo && git commit -m one && |
| 276 | git config --add remote.up.mirror true && |
| 277 | test_must_fail git push up main |
| 278 | ) |
| 279 | ' |
| 280 | |
| 281 | test_done |