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