t / t5531-deep-submodule-push.shon commit Merge branch 'rh/hide-prompt-in-ignored-directory' (e1ef7d1)
   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                test_must_fail git push --recurse-submodules=check ../pub.git master
  68        )
  69'
  70
  71test_expect_success 'push succeeds after commit was pushed to remote' '
  72        (
  73                cd work/gar/bage &&
  74                git push origin master
  75        ) &&
  76        (
  77                cd work &&
  78                git push --recurse-submodules=check ../pub.git master
  79        )
  80'
  81
  82test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
  83        (
  84                cd work/gar/bage &&
  85                >junk4 &&
  86                git add junk4 &&
  87                git commit -m "Fourth junk"
  88        ) &&
  89        (
  90                cd work &&
  91                git branch branch2 &&
  92                git add gar/bage &&
  93                git commit -m "Fourth commit for gar/bage" &&
  94                git checkout branch2 &&
  95                (
  96                        cd gar/bage &&
  97                        git checkout HEAD~1
  98                ) &&
  99                >junk1 &&
 100                git add junk1 &&
 101                git commit -m "First junk" &&
 102                test_must_fail git push --recurse-submodules=check ../pub.git
 103        )
 104'
 105
 106test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
 107        git init --bare a
 108        git clone a a1 &&
 109        (
 110                cd a1 &&
 111                git init b
 112                (
 113                        cd b &&
 114                        >junk &&
 115                        git add junk &&
 116                        git commit -m "initial"
 117                ) &&
 118                git add b &&
 119                git commit -m "added submodule" &&
 120                git push --recurse-submodule=check origin master
 121        )
 122'
 123
 124test_expect_success 'push unpushed submodules when not needed' '
 125        (
 126                cd work &&
 127                (
 128                        cd gar/bage &&
 129                        git checkout master &&
 130                        >junk5 &&
 131                        git add junk5 &&
 132                        git commit -m "Fifth junk" &&
 133                        git push &&
 134                        git rev-parse origin/master >../../../expected
 135                ) &&
 136                git checkout master &&
 137                git add gar/bage &&
 138                git commit -m "Fifth commit for gar/bage" &&
 139                git push --recurse-submodules=on-demand ../pub.git master
 140        ) &&
 141        (
 142                cd submodule.git &&
 143                git rev-parse master >../actual
 144        ) &&
 145        test_cmp expected actual
 146'
 147
 148test_expect_success 'push unpushed submodules when not needed 2' '
 149        (
 150                cd submodule.git &&
 151                git rev-parse master >../expected
 152        ) &&
 153        (
 154                cd work &&
 155                (
 156                        cd gar/bage &&
 157                        >junk6 &&
 158                        git add junk6 &&
 159                        git commit -m "Sixth junk"
 160                ) &&
 161                >junk2 &&
 162                git add junk2 &&
 163                git commit -m "Second junk for work" &&
 164                git push --recurse-submodules=on-demand ../pub.git master
 165        ) &&
 166        (
 167                cd submodule.git &&
 168                git rev-parse master >../actual
 169        ) &&
 170        test_cmp expected actual
 171'
 172
 173test_expect_success 'push unpushed submodules recursively' '
 174        (
 175                cd work &&
 176                (
 177                        cd gar/bage &&
 178                        git checkout master &&
 179                        > junk7 &&
 180                        git add junk7 &&
 181                        git commit -m "Seventh junk" &&
 182                        git rev-parse master >../../../expected
 183                ) &&
 184                git checkout master &&
 185                git add gar/bage &&
 186                git commit -m "Seventh commit for gar/bage" &&
 187                git push --recurse-submodules=on-demand ../pub.git master
 188        ) &&
 189        (
 190                cd submodule.git &&
 191                git rev-parse master >../actual
 192        ) &&
 193        test_cmp expected actual
 194'
 195
 196test_expect_success 'push unpushable submodule recursively fails' '
 197        (
 198                cd work &&
 199                (
 200                        cd gar/bage &&
 201                        git rev-parse origin/master >../../../expected &&
 202                        git checkout master~0 &&
 203                        > junk8 &&
 204                        git add junk8 &&
 205                        git commit -m "Eighth junk"
 206                ) &&
 207                git add gar/bage &&
 208                git commit -m "Eighth commit for gar/bage" &&
 209                test_must_fail git push --recurse-submodules=on-demand ../pub.git master
 210        ) &&
 211        (
 212                cd submodule.git &&
 213                git rev-parse master >../actual
 214        ) &&
 215        test_cmp expected actual
 216'
 217
 218test_done