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