t / t5531-deep-submodule-push.shon commit push: add recurseSubmodules config option (b33a15b)
   1#!/bin/sh
   2
   3test_description='unpack-objects'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8        mkdir pub.git &&
   9        GIT_DIR=pub.git git init --bare &&
  10        GIT_DIR=pub.git git config receive.fsckobjects true &&
  11        mkdir work &&
  12        (
  13                cd work &&
  14                git init &&
  15                git config push.default matching &&
  16                mkdir -p gar/bage &&
  17                (
  18                        cd gar/bage &&
  19                        git init &&
  20                        git config push.default matching &&
  21                        >junk &&
  22                        git add junk &&
  23                        git commit -m "Initial junk"
  24                ) &&
  25                git add gar/bage &&
  26                git commit -m "Initial superproject"
  27        )
  28'
  29
  30test_expect_success push '
  31        (
  32                cd work &&
  33                git push ../pub.git master
  34        )
  35'
  36
  37test_expect_success 'push if submodule has no remote' '
  38        (
  39                cd work/gar/bage &&
  40                >junk2 &&
  41                git add junk2 &&
  42                git commit -m "Second junk"
  43        ) &&
  44        (
  45                cd work &&
  46                git add gar/bage &&
  47                git commit -m "Second commit for gar/bage" &&
  48                git push --recurse-submodules=check ../pub.git master
  49        )
  50'
  51
  52test_expect_success 'push fails if submodule commit not on remote' '
  53        (
  54                cd work/gar &&
  55                git clone --bare bage ../../submodule.git &&
  56                cd bage &&
  57                git remote add origin ../../../submodule.git &&
  58                git fetch &&
  59                >junk3 &&
  60                git add junk3 &&
  61                git commit -m "Third junk"
  62        ) &&
  63        (
  64                cd work &&
  65                git add gar/bage &&
  66                git commit -m "Third commit for gar/bage" &&
  67                # the push should fail with --recurse-submodules=check
  68                # on the command line...
  69                test_must_fail git push --recurse-submodules=check ../pub.git master &&
  70
  71                # ...or if specified in the configuration..
  72                test_must_fail git -c push.recurseSubmodules=check push ../pub.git master
  73        )
  74'
  75
  76test_expect_success 'push succeeds after commit was pushed to remote' '
  77        (
  78                cd work/gar/bage &&
  79                git push origin master
  80        ) &&
  81        (
  82                cd work &&
  83                git push --recurse-submodules=check ../pub.git master
  84        )
  85'
  86
  87test_expect_success 'push succeeds if submodule commit not on remote but using on-demand on command line' '
  88        (
  89                cd work/gar/bage &&
  90                >recurse-on-demand-on-command-line &&
  91                git add recurse-on-demand-on-command-line &&
  92                git commit -m "Recurse on-demand on command line junk"
  93        ) &&
  94        (
  95                cd work &&
  96                git add gar/bage &&
  97                git commit -m "Recurse on-demand on command line for gar/bage" &&
  98                git push --recurse-submodules=on-demand ../pub.git master &&
  99                # Check that the supermodule commit got there
 100                git fetch ../pub.git &&
 101                git diff --quiet FETCH_HEAD master &&
 102                # Check that the submodule commit got there too
 103                cd gar/bage &&
 104                git diff --quiet origin/master master
 105        )
 106'
 107
 108test_expect_success 'push succeeds if submodule commit not on remote but using on-demand from config' '
 109        (
 110                cd work/gar/bage &&
 111                >recurse-on-demand-from-config &&
 112                git add recurse-on-demand-from-config &&
 113                git commit -m "Recurse on-demand from config junk"
 114        ) &&
 115        (
 116                cd work &&
 117                git add gar/bage &&
 118                git commit -m "Recurse on-demand from config for gar/bage" &&
 119                git -c push.recurseSubmodules=on-demand push ../pub.git master &&
 120                # Check that the supermodule commit got there
 121                git fetch ../pub.git &&
 122                git diff --quiet FETCH_HEAD master &&
 123                # Check that the submodule commit got there too
 124                cd gar/bage &&
 125                git diff --quiet origin/master master
 126        )
 127'
 128
 129test_expect_success 'push fails if submodule commit not on remote using check from cmdline overriding config' '
 130        (
 131                cd work/gar/bage &&
 132                >recurse-check-on-command-line-overriding-config &&
 133                git add recurse-check-on-command-line-overriding-config &&
 134                git commit -m "Recurse on command-line overridiing config junk"
 135        ) &&
 136        (
 137                cd work &&
 138                git add gar/bage &&
 139                git commit -m "Recurse on command-line overriding config for gar/bage" &&
 140                test_must_fail git -c push.recurseSubmodules=on-demand push --recurse-submodules=check ../pub.git master &&
 141                # Check that the supermodule commit did not get there
 142                git fetch ../pub.git &&
 143                git diff --quiet FETCH_HEAD master^ &&
 144                # Check that the submodule commit did not get there
 145                cd gar/bage &&
 146                git diff --quiet origin/master master^
 147        )
 148'
 149
 150test_expect_success 'push succeeds if submodule commit not on remote using on-demand from cmdline overriding config' '
 151        (
 152                cd work/gar/bage &&
 153                >recurse-on-demand-on-command-line-overriding-config &&
 154                git add recurse-on-demand-on-command-line-overriding-config &&
 155                git commit -m "Recurse on-demand on command-line overriding config junk"
 156        ) &&
 157        (
 158                cd work &&
 159                git add gar/bage &&
 160                git commit -m "Recurse on-demand on command-line overriding config for gar/bage" &&
 161                git -c push.recurseSubmodules=check push --recurse-submodules=on-demand ../pub.git master &&
 162                # Check that the supermodule commit got there
 163                git fetch ../pub.git &&
 164                git diff --quiet FETCH_HEAD master &&
 165                # Check that the submodule commit got there
 166                cd gar/bage &&
 167                git diff --quiet origin/master master
 168        )
 169'
 170
 171test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline overriding config' '
 172        (
 173                cd work/gar/bage &&
 174                >recurse-disable-on-command-line-overriding-config &&
 175                git add recurse-disable-on-command-line-overriding-config &&
 176                git commit -m "Recurse disable on command-line overriding config junk"
 177        ) &&
 178        (
 179                cd work &&
 180                git add gar/bage &&
 181                git commit -m "Recurse disable on command-line overriding config for gar/bage" &&
 182                git -c push.recurseSubmodules=check push --recurse-submodules=no ../pub.git master &&
 183                # Check that the supermodule commit got there
 184                git fetch ../pub.git &&
 185                git diff --quiet FETCH_HEAD master &&
 186                # But that the submodule commit did not
 187                ( cd gar/bage && git diff --quiet origin/master master^ ) &&
 188                # Now push it to avoid confusing future tests
 189                git push --recurse-submodules=on-demand ../pub.git master
 190        )
 191'
 192
 193test_expect_success 'push succeeds if submodule commit disabling recursion from cmdline (alternative form) overriding config' '
 194        (
 195                cd work/gar/bage &&
 196                >recurse-disable-on-command-line-alt-overriding-config &&
 197                git add recurse-disable-on-command-line-alt-overriding-config &&
 198                git commit -m "Recurse disable on command-line alternative overriding config junk"
 199        ) &&
 200        (
 201                cd work &&
 202                git add gar/bage &&
 203                git commit -m "Recurse disable on command-line alternative overriding config for gar/bage" &&
 204                git -c push.recurseSubmodules=check push --no-recurse-submodules ../pub.git master &&
 205                # Check that the supermodule commit got there
 206                git fetch ../pub.git &&
 207                git diff --quiet FETCH_HEAD master &&
 208                # But that the submodule commit did not
 209                ( cd gar/bage && git diff --quiet origin/master master^ ) &&
 210                # Now push it to avoid confusing future tests
 211                git push --recurse-submodules=on-demand ../pub.git master
 212        )
 213'
 214
 215test_expect_success 'push fails if recurse submodules option passed as yes' '
 216        (
 217                cd work/gar/bage &&
 218                >recurse-push-fails-if-recurse-submodules-passed-as-yes &&
 219                git add recurse-push-fails-if-recurse-submodules-passed-as-yes &&
 220                git commit -m "Recurse push fails if recurse submodules option passed as yes"
 221        ) &&
 222        (
 223                cd work &&
 224                git add gar/bage &&
 225                git commit -m "Recurse push fails if recurse submodules option passed as yes for gar/bage" &&
 226                test_must_fail git push --recurse-submodules=yes ../pub.git master &&
 227                test_must_fail git -c push.recurseSubmodules=yes push ../pub.git master &&
 228                git push --recurse-submodules=on-demand ../pub.git master
 229        )
 230'
 231
 232test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
 233        (
 234                cd work/gar/bage &&
 235                >junk4 &&
 236                git add junk4 &&
 237                git commit -m "Fourth junk"
 238        ) &&
 239        (
 240                cd work &&
 241                git branch branch2 &&
 242                git add gar/bage &&
 243                git commit -m "Fourth commit for gar/bage" &&
 244                git checkout branch2 &&
 245                (
 246                        cd gar/bage &&
 247                        git checkout HEAD~1
 248                ) &&
 249                >junk1 &&
 250                git add junk1 &&
 251                git commit -m "First junk" &&
 252                test_must_fail git push --recurse-submodules=check ../pub.git
 253        )
 254'
 255
 256test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
 257        git init --bare a &&
 258        git clone a a1 &&
 259        (
 260                cd a1 &&
 261                git init b
 262                (
 263                        cd b &&
 264                        >junk &&
 265                        git add junk &&
 266                        git commit -m "initial"
 267                ) &&
 268                git add b &&
 269                git commit -m "added submodule" &&
 270                git push --recurse-submodule=check origin master
 271        )
 272'
 273
 274test_expect_success 'push unpushed submodules when not needed' '
 275        (
 276                cd work &&
 277                (
 278                        cd gar/bage &&
 279                        git checkout master &&
 280                        >junk5 &&
 281                        git add junk5 &&
 282                        git commit -m "Fifth junk" &&
 283                        git push &&
 284                        git rev-parse origin/master >../../../expected
 285                ) &&
 286                git checkout master &&
 287                git add gar/bage &&
 288                git commit -m "Fifth commit for gar/bage" &&
 289                git push --recurse-submodules=on-demand ../pub.git master
 290        ) &&
 291        (
 292                cd submodule.git &&
 293                git rev-parse master >../actual
 294        ) &&
 295        test_cmp expected actual
 296'
 297
 298test_expect_success 'push unpushed submodules when not needed 2' '
 299        (
 300                cd submodule.git &&
 301                git rev-parse master >../expected
 302        ) &&
 303        (
 304                cd work &&
 305                (
 306                        cd gar/bage &&
 307                        >junk6 &&
 308                        git add junk6 &&
 309                        git commit -m "Sixth junk"
 310                ) &&
 311                >junk2 &&
 312                git add junk2 &&
 313                git commit -m "Second junk for work" &&
 314                git push --recurse-submodules=on-demand ../pub.git master
 315        ) &&
 316        (
 317                cd submodule.git &&
 318                git rev-parse master >../actual
 319        ) &&
 320        test_cmp expected actual
 321'
 322
 323test_expect_success 'push unpushed submodules recursively' '
 324        (
 325                cd work &&
 326                (
 327                        cd gar/bage &&
 328                        git checkout master &&
 329                        > junk7 &&
 330                        git add junk7 &&
 331                        git commit -m "Seventh junk" &&
 332                        git rev-parse master >../../../expected
 333                ) &&
 334                git checkout master &&
 335                git add gar/bage &&
 336                git commit -m "Seventh commit for gar/bage" &&
 337                git push --recurse-submodules=on-demand ../pub.git master
 338        ) &&
 339        (
 340                cd submodule.git &&
 341                git rev-parse master >../actual
 342        ) &&
 343        test_cmp expected actual
 344'
 345
 346test_expect_success 'push unpushable submodule recursively fails' '
 347        (
 348                cd work &&
 349                (
 350                        cd gar/bage &&
 351                        git rev-parse origin/master >../../../expected &&
 352                        git checkout master~0 &&
 353                        > junk8 &&
 354                        git add junk8 &&
 355                        git commit -m "Eighth junk"
 356                ) &&
 357                git add gar/bage &&
 358                git commit -m "Eighth commit for gar/bage" &&
 359                test_must_fail git push --recurse-submodules=on-demand ../pub.git master
 360        ) &&
 361        (
 362                cd submodule.git &&
 363                git rev-parse master >../actual
 364        ) &&
 365        test_cmp expected actual
 366'
 367
 368test_done