t / t7403-submodule-sync.shon commit submodule: improve submodule_has_commits() (7c8d2b0)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 David Aguilar
   4#
   5
   6test_description='git submodule sync
   7
   8These tests exercise the "git submodule sync" subcommand.
   9'
  10
  11. ./test-lib.sh
  12
  13test_expect_success setup '
  14        echo file >file &&
  15        git add file &&
  16        test_tick &&
  17        git commit -m upstream &&
  18        git clone . super &&
  19        git clone super submodule &&
  20        (
  21                cd submodule &&
  22                git submodule add ../submodule sub-submodule &&
  23                test_tick &&
  24                git commit -m "sub-submodule"
  25        ) &&
  26        (
  27                cd super &&
  28                git submodule add ../submodule submodule &&
  29                test_tick &&
  30                git commit -m "submodule"
  31        ) &&
  32        git clone super super-clone &&
  33        (
  34                cd super-clone &&
  35                git submodule update --init --recursive
  36        ) &&
  37        git clone super empty-clone &&
  38        (
  39                cd empty-clone &&
  40                git submodule init
  41        ) &&
  42        git clone super top-only-clone &&
  43        git clone super relative-clone &&
  44        (
  45                cd relative-clone &&
  46                git submodule update --init --recursive
  47        ) &&
  48        git clone super recursive-clone &&
  49        (
  50                cd recursive-clone &&
  51                git submodule update --init --recursive
  52        )
  53'
  54
  55test_expect_success 'change submodule' '
  56        (
  57                cd submodule &&
  58                echo second line >>file &&
  59                test_tick &&
  60                git commit -a -m "change submodule"
  61        )
  62'
  63
  64reset_submodule_urls () {
  65        (
  66                root=$(pwd) &&
  67                cd super-clone/submodule &&
  68                git config remote.origin.url "$root/submodule"
  69        ) &&
  70        (
  71                root=$(pwd) &&
  72                cd super-clone/submodule/sub-submodule &&
  73                git config remote.origin.url "$root/submodule"
  74        )
  75}
  76
  77test_expect_success 'change submodule url' '
  78        (
  79                cd super &&
  80                cd submodule &&
  81                git checkout master &&
  82                git pull
  83        ) &&
  84        mv submodule moved-submodule &&
  85        (
  86                cd moved-submodule &&
  87                git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
  88                test_tick &&
  89                git commit -a -m moved-sub-submodule
  90        ) &&
  91        (
  92                cd super &&
  93                git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
  94                test_tick &&
  95                git commit -a -m moved-submodule
  96        )
  97'
  98
  99test_expect_success '"git submodule sync" should update submodule URLs' '
 100        (
 101                cd super-clone &&
 102                git pull --no-recurse-submodules &&
 103                git submodule sync
 104        ) &&
 105        test -d "$(
 106                cd super-clone/submodule &&
 107                git config remote.origin.url
 108        )" &&
 109        test ! -d "$(
 110                cd super-clone/submodule/sub-submodule &&
 111                git config remote.origin.url
 112        )" &&
 113        (
 114                cd super-clone/submodule &&
 115                git checkout master &&
 116                git pull
 117        ) &&
 118        (
 119                cd super-clone &&
 120                test -d "$(git config submodule.submodule.url)"
 121        )
 122'
 123
 124test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
 125        (
 126                cd super-clone &&
 127                (
 128                        cd submodule &&
 129                        git pull --no-recurse-submodules
 130                ) &&
 131                git submodule sync --recursive
 132        ) &&
 133        test -d "$(
 134                cd super-clone/submodule &&
 135                git config remote.origin.url
 136        )" &&
 137        test -d "$(
 138                cd super-clone/submodule/sub-submodule &&
 139                git config remote.origin.url
 140        )" &&
 141        (
 142                cd super-clone/submodule/sub-submodule &&
 143                git checkout master &&
 144                git pull
 145        )
 146'
 147
 148test_expect_success 'reset submodule URLs' '
 149        reset_submodule_urls super-clone
 150'
 151
 152test_expect_success '"git submodule sync" should update submodule URLs - subdirectory' '
 153        (
 154                cd super-clone &&
 155                git pull --no-recurse-submodules &&
 156                mkdir -p sub &&
 157                cd sub &&
 158                git submodule sync >../../output
 159        ) &&
 160        test_i18ngrep "\\.\\./submodule" output &&
 161        test -d "$(
 162                cd super-clone/submodule &&
 163                git config remote.origin.url
 164        )" &&
 165        test ! -d "$(
 166                cd super-clone/submodule/sub-submodule &&
 167                git config remote.origin.url
 168        )" &&
 169        (
 170                cd super-clone/submodule &&
 171                git checkout master &&
 172                git pull
 173        ) &&
 174        (
 175                cd super-clone &&
 176                test -d "$(git config submodule.submodule.url)"
 177        )
 178'
 179
 180test_expect_success '"git submodule sync --recursive" should update all submodule URLs - subdirectory' '
 181        (
 182                cd super-clone &&
 183                (
 184                        cd submodule &&
 185                        git pull --no-recurse-submodules
 186                ) &&
 187                mkdir -p sub &&
 188                cd sub &&
 189                git submodule sync --recursive >../../output
 190        ) &&
 191        test_i18ngrep "\\.\\./submodule/sub-submodule" output &&
 192        test -d "$(
 193                cd super-clone/submodule &&
 194                git config remote.origin.url
 195        )" &&
 196        test -d "$(
 197                cd super-clone/submodule/sub-submodule &&
 198                git config remote.origin.url
 199        )" &&
 200        (
 201                cd super-clone/submodule/sub-submodule &&
 202                git checkout master &&
 203                git pull
 204        )
 205'
 206
 207test_expect_success '"git submodule sync" should update known submodule URLs' '
 208        (
 209                cd empty-clone &&
 210                git pull &&
 211                git submodule sync &&
 212                test -d "$(git config submodule.submodule.url)"
 213        )
 214'
 215
 216test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
 217        (
 218                cd top-only-clone &&
 219                git pull &&
 220                git submodule sync &&
 221                test -z "$(git config submodule.submodule.url)" &&
 222                git submodule sync submodule &&
 223                test -z "$(git config submodule.submodule.url)"
 224        )
 225'
 226
 227test_expect_success '"git submodule sync" handles origin URL of the form foo' '
 228        (
 229                cd relative-clone &&
 230                git remote set-url origin foo &&
 231                git submodule sync &&
 232                (
 233                        cd submodule &&
 234                        #actual fails with: "cannot strip off url foo
 235                        test "$(git config remote.origin.url)" = "../submodule"
 236                )
 237        )
 238'
 239
 240test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
 241        (
 242                cd relative-clone &&
 243                git remote set-url origin foo/bar &&
 244                git submodule sync &&
 245                (
 246                        cd submodule &&
 247                        #actual foo/submodule
 248                        test "$(git config remote.origin.url)" = "../foo/submodule"
 249                ) &&
 250                (
 251                        cd submodule/sub-submodule &&
 252                        test "$(git config remote.origin.url)" != "../../foo/submodule"
 253                )
 254        )
 255'
 256
 257test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
 258        (
 259                cd recursive-clone &&
 260                git remote set-url origin foo/bar &&
 261                git submodule sync --recursive &&
 262                (
 263                        cd submodule &&
 264                        #actual foo/submodule
 265                        test "$(git config remote.origin.url)" = "../foo/submodule"
 266                ) &&
 267                (
 268                        cd submodule/sub-submodule &&
 269                        test "$(git config remote.origin.url)" = "../../foo/submodule"
 270                )
 271        )
 272'
 273
 274test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
 275        (
 276                cd relative-clone &&
 277                git remote set-url origin ./foo &&
 278                git submodule sync &&
 279                (
 280                        cd submodule &&
 281                        #actual ./submodule
 282                        test "$(git config remote.origin.url)" = "../submodule"
 283                )
 284        )
 285'
 286
 287test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
 288        (
 289                cd relative-clone &&
 290                git remote set-url origin ./foo/bar &&
 291                git submodule sync &&
 292                (
 293                        cd submodule &&
 294                        #actual ./foo/submodule
 295                        test "$(git config remote.origin.url)" = "../foo/submodule"
 296                )
 297        )
 298'
 299
 300test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
 301        (
 302                cd relative-clone &&
 303                git remote set-url origin ../foo &&
 304                git submodule sync &&
 305                (
 306                        cd submodule &&
 307                        #actual ../submodule
 308                        test "$(git config remote.origin.url)" = "../../submodule"
 309                )
 310        )
 311'
 312
 313test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
 314        (
 315                cd relative-clone &&
 316                git remote set-url origin ../foo/bar &&
 317                git submodule sync &&
 318                (
 319                        cd submodule &&
 320                        #actual ../foo/submodule
 321                        test "$(git config remote.origin.url)" = "../../foo/submodule"
 322                )
 323        )
 324'
 325
 326test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
 327        (
 328                cd relative-clone &&
 329                git remote set-url origin ../foo/bar &&
 330                mkdir -p a/b/c &&
 331                (
 332                        cd a/b/c &&
 333                        git init &&
 334                        >.gitignore &&
 335                        git add .gitignore &&
 336                        test_tick &&
 337                        git commit -m "initial commit"
 338                ) &&
 339                git submodule add ../bar/a/b/c ./a/b/c &&
 340                git submodule sync &&
 341                (
 342                        cd a/b/c &&
 343                        #actual ../foo/bar/a/b/c
 344                        test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
 345                )
 346        )
 347'
 348
 349
 350test_done