t / t5531-deep-submodule-push.shon commit Merge branch 'xq/credential-osxkeychain' (cb4d6c2)
   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                mkdir -p gar/bage &&
  16                (
  17                        cd gar/bage &&
  18                        git init &&
  19                        git config push.default matching &&
  20                        >junk &&
  21                        git add junk &&
  22                        git commit -m "Initial junk"
  23                ) &&
  24                git add gar/bage &&
  25                git commit -m "Initial superproject"
  26        )
  27'
  28
  29test_expect_success push '
  30        (
  31                cd work &&
  32                git push ../pub.git master
  33        )
  34'
  35
  36test_expect_success 'push if submodule has no remote' '
  37        (
  38                cd work/gar/bage &&
  39                >junk2 &&
  40                git add junk2 &&
  41                git commit -m "Second junk"
  42        ) &&
  43        (
  44                cd work &&
  45                git add gar/bage &&
  46                git commit -m "Second commit for gar/bage" &&
  47                git push --recurse-submodules=check ../pub.git master
  48        )
  49'
  50
  51test_expect_success 'push fails if submodule commit not on remote' '
  52        (
  53                cd work/gar &&
  54                git clone --bare bage ../../submodule.git &&
  55                cd bage &&
  56                git remote add origin ../../../submodule.git &&
  57                git fetch &&
  58                >junk3 &&
  59                git add junk3 &&
  60                git commit -m "Third junk"
  61        ) &&
  62        (
  63                cd work &&
  64                git add gar/bage &&
  65                git commit -m "Third commit for gar/bage" &&
  66                test_must_fail git push --recurse-submodules=check ../pub.git master
  67        )
  68'
  69
  70test_expect_success 'push succeeds after commit was pushed to remote' '
  71        (
  72                cd work/gar/bage &&
  73                git push origin master
  74        ) &&
  75        (
  76                cd work &&
  77                git push --recurse-submodules=check ../pub.git master
  78        )
  79'
  80
  81test_expect_success 'push fails when commit on multiple branches if one branch has no remote' '
  82        (
  83                cd work/gar/bage &&
  84                >junk4 &&
  85                git add junk4 &&
  86                git commit -m "Fourth junk"
  87        ) &&
  88        (
  89                cd work &&
  90                git branch branch2 &&
  91                git add gar/bage &&
  92                git commit -m "Fourth commit for gar/bage" &&
  93                git checkout branch2 &&
  94                (
  95                        cd gar/bage &&
  96                        git checkout HEAD~1
  97                ) &&
  98                >junk1 &&
  99                git add junk1 &&
 100                git commit -m "First junk" &&
 101                test_must_fail git push --recurse-submodules=check ../pub.git
 102        )
 103'
 104
 105test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' '
 106        git init --bare a
 107        git clone a a1 &&
 108        (
 109                cd a1 &&
 110                git init b
 111                (
 112                        cd b &&
 113                        >junk &&
 114                        git add junk &&
 115                        git commit -m "initial"
 116                ) &&
 117                git add b &&
 118                git commit -m "added submodule" &&
 119                git push --recurse-submodule=check origin master
 120        )
 121'
 122
 123test_expect_success 'push unpushed submodules when not needed' '
 124        (
 125                cd work &&
 126                (
 127                        cd gar/bage &&
 128                        git checkout master &&
 129                        >junk5 &&
 130                        git add junk5 &&
 131                        git commit -m "Fifth junk" &&
 132                        git push &&
 133                        git rev-parse origin/master >../../../expected
 134                ) &&
 135                git checkout master &&
 136                git add gar/bage &&
 137                git commit -m "Fifth commit for gar/bage" &&
 138                git push --recurse-submodules=on-demand ../pub.git master
 139        ) &&
 140        (
 141                cd submodule.git &&
 142                git rev-parse master >../actual
 143        ) &&
 144        test_cmp expected actual
 145'
 146
 147test_expect_success 'push unpushed submodules when not needed 2' '
 148        (
 149                cd submodule.git &&
 150                git rev-parse master >../expected
 151        ) &&
 152        (
 153                cd work &&
 154                (
 155                        cd gar/bage &&
 156                        >junk6 &&
 157                        git add junk6 &&
 158                        git commit -m "Sixth junk"
 159                ) &&
 160                >junk2 &&
 161                git add junk2 &&
 162                git commit -m "Second junk for work" &&
 163                git push --recurse-submodules=on-demand ../pub.git master
 164        ) &&
 165        (
 166                cd submodule.git &&
 167                git rev-parse master >../actual
 168        ) &&
 169        test_cmp expected actual
 170'
 171
 172test_expect_success 'push unpushed submodules recursively' '
 173        (
 174                cd work &&
 175                (
 176                        cd gar/bage &&
 177                        git checkout master &&
 178                        > junk7 &&
 179                        git add junk7 &&
 180                        git commit -m "Seventh junk" &&
 181                        git rev-parse master >../../../expected
 182                ) &&
 183                git checkout master &&
 184                git add gar/bage &&
 185                git commit -m "Seventh commit for gar/bage" &&
 186                git push --recurse-submodules=on-demand ../pub.git master
 187        ) &&
 188        (
 189                cd submodule.git &&
 190                git rev-parse master >../actual
 191        ) &&
 192        test_cmp expected actual
 193'
 194
 195test_expect_success 'push unpushable submodule recursively fails' '
 196        (
 197                cd work &&
 198                (
 199                        cd gar/bage &&
 200                        git rev-parse origin/master >../../../expected &&
 201                        git checkout master~0 &&
 202                        > junk8 &&
 203                        git add junk8 &&
 204                        git commit -m "Eighth junk"
 205                ) &&
 206                git add gar/bage &&
 207                git commit -m "Eighth commit for gar/bage" &&
 208                test_must_fail git push --recurse-submodules=on-demand ../pub.git master
 209        ) &&
 210        (
 211                cd submodule.git &&
 212                git rev-parse master >../actual
 213        ) &&
 214        test_cmp expected actual
 215'
 216
 217test_done