t7403-submodule-sync.sh 5.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/bin/sh
#
# Copyright (c) 2008 David Aguilar
#

test_description='git submodule sync

These tests exercise the "git submodule sync" subcommand.
'

. ./test-lib.sh

test_expect_success setup '
	echo file > file &&
	git add file &&
	test_tick &&
Jens Lehmann's avatar
Jens Lehmann committed
17
	git commit -m upstream &&
18 19
	git clone . super &&
	git clone super submodule &&
20 21 22 23 24
	(cd submodule &&
	 git submodule add ../submodule sub-submodule &&
	 test_tick &&
	 git commit -m "sub-submodule"
	) &&
25 26 27 28 29 30
	(cd super &&
	 git submodule add ../submodule submodule &&
	 test_tick &&
	 git commit -m "submodule"
	) &&
	git clone super super-clone &&
31
	(cd super-clone && git submodule update --init --recursive) &&
32
	git clone super empty-clone &&
33
	(cd empty-clone && git submodule init) &&
34 35
	git clone super top-only-clone &&
	git clone super relative-clone &&
36 37 38
	(cd relative-clone && git submodule update --init --recursive) &&
	git clone super recursive-clone &&
	(cd recursive-clone && git submodule update --init --recursive)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
'

test_expect_success 'change submodule' '
	(cd submodule &&
	 echo second line >> file &&
	 test_tick &&
	 git commit -a -m "change submodule"
	)
'

test_expect_success 'change submodule url' '
	(cd super &&
	 cd submodule &&
	 git checkout master &&
	 git pull
	) &&
	mv submodule moved-submodule &&
56 57 58 59 60
	(cd moved-submodule &&
	 git config -f .gitmodules submodule.sub-submodule.url ../moved-submodule &&
	 test_tick &&
	 git commit -a -m moved-sub-submodule
	) &&
61
	(cd super &&
Jens Lehmann's avatar
Jens Lehmann committed
62
	 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
63 64 65 66 67 68 69
	 test_tick &&
	 git commit -a -m moved-submodule
	)
'

test_expect_success '"git submodule sync" should update submodule URLs' '
	(cd super-clone &&
70
	 git pull --no-recurse-submodules &&
71 72
	 git submodule sync
	) &&
73 74 75
	test -d "$(cd super-clone/submodule &&
	 git config remote.origin.url
	)" &&
76 77 78
	test ! -d "$(cd super-clone/submodule/sub-submodule &&
	 git config remote.origin.url
	)" &&
79 80 81
	(cd super-clone/submodule &&
	 git checkout master &&
	 git pull
82 83 84
	) &&
	(cd super-clone &&
	 test -d "$(git config submodule.submodule.url)"
85 86 87
	)
'

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
test_expect_success '"git submodule sync --recursive" should update all submodule URLs' '
	(cd super-clone &&
	 (cd submodule &&
	  git pull --no-recurse-submodules
	 ) &&
	 git submodule sync --recursive
	) &&
	test -d "$(cd super-clone/submodule &&
	 git config remote.origin.url
	)" &&
	test -d "$(cd super-clone/submodule/sub-submodule &&
	 git config remote.origin.url
	)" &&
	(cd super-clone/submodule/sub-submodule &&
	 git checkout master &&
	 git pull
	)
'

107
test_expect_success '"git submodule sync" should update known submodule URLs' '
108 109 110 111 112 113 114
	(cd empty-clone &&
	 git pull &&
	 git submodule sync &&
	 test -d "$(git config submodule.submodule.url)"
	)
'

115 116 117 118 119 120 121 122 123 124
test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
	(cd top-only-clone &&
	 git pull &&
	 git submodule sync &&
	 test -z "$(git config submodule.submodule.url)" &&
	 git submodule sync submodule &&
	 test -z "$(git config submodule.submodule.url)"
	)
'

125
test_expect_success '"git submodule sync" handles origin URL of the form foo' '
126 127 128 129 130 131 132 133 134 135
	(cd relative-clone &&
	 git remote set-url origin foo &&
	 git submodule sync &&
	(cd submodule &&
	 #actual fails with: "cannot strip off url foo
	 test "$(git config remote.origin.url)" = "../submodule"
	)
	)
'

136
test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
137 138 139 140 141 142 143
	(cd relative-clone &&
	 git remote set-url origin foo/bar &&
	 git submodule sync &&
	(cd submodule &&
	 #actual foo/submodule
	 test "$(git config remote.origin.url)" = "../foo/submodule"
	)
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
	(cd submodule/sub-submodule &&
	 test "$(git config remote.origin.url)" != "../../foo/submodule"
	)
	)
'

test_expect_success '"git submodule sync --recursive" propagates changes in origin' '
	(cd recursive-clone &&
	 git remote set-url origin foo/bar &&
	 git submodule sync --recursive &&
	(cd submodule &&
	 #actual foo/submodule
	 test "$(git config remote.origin.url)" = "../foo/submodule"
	)
	(cd submodule/sub-submodule &&
	 test "$(git config remote.origin.url)" = "../../foo/submodule"
	)
161 162 163
	)
'

164
test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
165 166 167 168 169 170 171 172 173 174
	(cd relative-clone &&
	 git remote set-url origin ./foo &&
	 git submodule sync &&
	(cd submodule &&
	 #actual ./submodule
	 test "$(git config remote.origin.url)" = "../submodule"
	)
	)
'

175
test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
176 177 178 179 180 181 182 183 184 185
	(cd relative-clone &&
	 git remote set-url origin ./foo/bar &&
	 git submodule sync &&
	(cd submodule &&
	 #actual ./foo/submodule
	 test "$(git config remote.origin.url)" = "../foo/submodule"
	)
	)
'

186
test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
187 188 189 190 191 192 193 194 195 196
	(cd relative-clone &&
	 git remote set-url origin ../foo &&
	 git submodule sync &&
	(cd submodule &&
	 #actual ../submodule
	 test "$(git config remote.origin.url)" = "../../submodule"
	)
	)
'

197
test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
198 199 200 201 202 203 204 205 206 207
	(cd relative-clone &&
	 git remote set-url origin ../foo/bar &&
	 git submodule sync &&
	(cd submodule &&
	 #actual ../foo/submodule
	 test "$(git config remote.origin.url)" = "../../foo/submodule"
	)
	)
'

208
test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
	(cd relative-clone &&
	 git remote set-url origin ../foo/bar &&
	 mkdir -p a/b/c &&
	 ( cd a/b/c &&
	   git init &&
	   :> .gitignore &&
	   git add .gitignore &&
	   test_tick &&
	   git commit -m "initial commit" ) &&
	 git submodule add ../bar/a/b/c ./a/b/c &&
	 git submodule sync &&
	(cd a/b/c &&
	 #actual ../foo/bar/a/b/c
	 test "$(git config remote.origin.url)" = "../../../../foo/bar/a/b/c"
	)
	)
'


228
test_done