t / t7403-submodule-sync.shon commit fetch-pack: eliminate spurious error messages (5f0fc64)
   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        (cd super &&
  21         git submodule add ../submodule submodule &&
  22         test_tick &&
  23         git commit -m "submodule"
  24        ) &&
  25        git clone super super-clone &&
  26        (cd super-clone && git submodule update --init) &&
  27        git clone super empty-clone &&
  28        (cd empty-clone && git submodule init) &&
  29        git clone super top-only-clone &&
  30        git clone super relative-clone &&
  31        (cd relative-clone && git submodule update --init)
  32'
  33
  34test_expect_success 'change submodule' '
  35        (cd submodule &&
  36         echo second line >> file &&
  37         test_tick &&
  38         git commit -a -m "change submodule"
  39        )
  40'
  41
  42test_expect_success 'change submodule url' '
  43        (cd super &&
  44         cd submodule &&
  45         git checkout master &&
  46         git pull
  47        ) &&
  48        mv submodule moved-submodule &&
  49        (cd super &&
  50         git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
  51         test_tick &&
  52         git commit -a -m moved-submodule
  53        )
  54'
  55
  56test_expect_success '"git submodule sync" should update submodule URLs' '
  57        (cd super-clone &&
  58         git pull --no-recurse-submodules &&
  59         git submodule sync
  60        ) &&
  61        test -d "$(cd super-clone/submodule &&
  62         git config remote.origin.url
  63        )" &&
  64        (cd super-clone/submodule &&
  65         git checkout master &&
  66         git pull
  67        ) &&
  68        (cd super-clone &&
  69         test -d "$(git config submodule.submodule.url)"
  70        )
  71'
  72
  73test_expect_success '"git submodule sync" should update known submodule URLs' '
  74        (cd empty-clone &&
  75         git pull &&
  76         git submodule sync &&
  77         test -d "$(git config submodule.submodule.url)"
  78        )
  79'
  80
  81test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
  82        (cd top-only-clone &&
  83         git pull &&
  84         git submodule sync &&
  85         test -z "$(git config submodule.submodule.url)" &&
  86         git submodule sync submodule &&
  87         test -z "$(git config submodule.submodule.url)"
  88        )
  89'
  90
  91test_expect_success '"git submodule sync" handles origin URL of the form foo' '
  92        (cd relative-clone &&
  93         git remote set-url origin foo &&
  94         git submodule sync &&
  95        (cd submodule &&
  96         #actual fails with: "cannot strip off url foo
  97         test "$(git config remote.origin.url)" = "../submodule"
  98        )
  99        )
 100'
 101
 102test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
 103        (cd relative-clone &&
 104         git remote set-url origin foo/bar &&
 105         git submodule sync &&
 106        (cd submodule &&
 107         #actual foo/submodule
 108         test "$(git config remote.origin.url)" = "../foo/submodule"
 109        )
 110        )
 111'
 112
 113test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
 114        (cd relative-clone &&
 115         git remote set-url origin ./foo &&
 116         git submodule sync &&
 117        (cd submodule &&
 118         #actual ./submodule
 119         test "$(git config remote.origin.url)" = "../submodule"
 120        )
 121        )
 122'
 123
 124test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
 125        (cd relative-clone &&
 126         git remote set-url origin ./foo/bar &&
 127         git submodule sync &&
 128        (cd submodule &&
 129         #actual ./foo/submodule
 130         test "$(git config remote.origin.url)" = "../foo/submodule"
 131        )
 132        )
 133'
 134
 135test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
 136        (cd relative-clone &&
 137         git remote set-url origin ../foo &&
 138         git submodule sync &&
 139        (cd submodule &&
 140         #actual ../submodule
 141         test "$(git config remote.origin.url)" = "../../submodule"
 142        )
 143        )
 144'
 145
 146test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
 147        (cd relative-clone &&
 148         git remote set-url origin ../foo/bar &&
 149         git submodule sync &&
 150        (cd submodule &&
 151         #actual ../foo/submodule
 152         test "$(git config remote.origin.url)" = "../../foo/submodule"
 153        )
 154        )
 155'
 156
 157test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
 158        (cd relative-clone &&
 159         git remote set-url origin ../foo/bar &&
 160         mkdir -p a/b/c &&
 161         ( cd a/b/c &&
 162           git init &&
 163           :> .gitignore &&
 164           git add .gitignore &&
 165           test_tick &&
 166           git commit -m "initial commit" ) &&
 167         git submodule add ../bar/a/b/c ./a/b/c &&
 168         git submodule sync &&
 169        (cd a/b/c &&
 170         #actual ../foo/bar/a/b/c
 171         test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
 172        )
 173        )
 174'
 175
 176
 177test_done