t7403-submodule-sync.sh 4.18 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 20 21 22 23 24 25
	git clone . super &&
	git clone super submodule &&
	(cd super &&
	 git submodule add ../submodule submodule &&
	 test_tick &&
	 git commit -m "submodule"
	) &&
	git clone super super-clone &&
26 27
	(cd super-clone && git submodule update --init) &&
	git clone super empty-clone &&
28
	(cd empty-clone && git submodule init) &&
29 30 31
	git clone super top-only-clone &&
	git clone super relative-clone &&
	(cd relative-clone && git submodule update --init)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
'

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 &&
	(cd super &&
Jens Lehmann's avatar
Jens Lehmann committed
50
	 git config -f .gitmodules submodule.submodule.url ../moved-submodule &&
51 52 53 54 55 56 57
	 test_tick &&
	 git commit -a -m moved-submodule
	)
'

test_expect_success '"git submodule sync" should update submodule URLs' '
	(cd super-clone &&
58
	 git pull --no-recurse-submodules &&
59 60
	 git submodule sync
	) &&
61 62 63
	test -d "$(cd super-clone/submodule &&
	 git config remote.origin.url
	)" &&
64 65 66
	(cd super-clone/submodule &&
	 git checkout master &&
	 git pull
67 68 69
	) &&
	(cd super-clone &&
	 test -d "$(git config submodule.submodule.url)"
70 71 72
	)
'

73
test_expect_success '"git submodule sync" should update known submodule URLs' '
74 75 76 77 78 79 80
	(cd empty-clone &&
	 git pull &&
	 git submodule sync &&
	 test -d "$(git config submodule.submodule.url)"
	)
'

81 82 83 84 85 86 87 88 89 90
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)"
	)
'

91
test_expect_success '"git submodule sync" handles origin URL of the form foo' '
92 93 94 95 96 97 98 99 100 101
	(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"
	)
	)
'

102
test_expect_success '"git submodule sync" handles origin URL of the form foo/bar' '
103 104 105 106 107 108 109 110 111 112
	(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"
	)
	)
'

113
test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
114 115 116 117 118 119 120 121 122 123
	(cd relative-clone &&
	 git remote set-url origin ./foo &&
	 git submodule sync &&
	(cd submodule &&
	 #actual ./submodule
	 test "$(git config remote.origin.url)" = "../submodule"
	)
	)
'

124
test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
125 126 127 128 129 130 131 132 133 134
	(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"
	)
	)
'

135
test_expect_success '"git submodule sync" handles origin URL of the form ../foo' '
136 137 138 139 140 141 142 143 144 145
	(cd relative-clone &&
	 git remote set-url origin ../foo &&
	 git submodule sync &&
	(cd submodule &&
	 #actual ../submodule
	 test "$(git config remote.origin.url)" = "../../submodule"
	)
	)
'

146
test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar' '
147 148 149 150 151 152 153 154 155 156
	(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"
	)
	)
'

157
test_expect_success '"git submodule sync" handles origin URL of the form ../foo/bar with deeply nested submodule' '
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
	(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"
	)
	)
'


177
test_done