index-pack.c: correctly initialize appended objects
[git/jnareb-git/bp-gitweb.git] / t / t7400-submodule-basic.sh
blob6c7b9024822024ca24f7d1ddea63c94d3aa016b0
1 #!/bin/sh
3 # Copyright (c) 2007 Lars Hjemli
6 test_description='Basic porcelain support for submodules
8 This test tries to verify basic sanity of the init, update and status
9 subcommands of git-submodule.
12 . ./test-lib.sh
15 # Test setup:
16 # -create a repository in directory init
17 # -add a couple of files
18 # -add directory init to 'superproject', this creates a DIRLINK entry
19 # -add a couple of regular files to enable testing of submodule filtering
20 # -mv init subrepo
21 # -add an entry to .gitmodules for submodule 'example'
23 test_expect_success 'Prepare submodule testing' '
24 : > t &&
25 git-add t &&
26 git-commit -m "initial commit" &&
27 git branch initial HEAD &&
28 mkdir init &&
29 cd init &&
30 git init &&
31 echo a >a &&
32 git add a &&
33 git-commit -m "submodule commit 1" &&
34 git-tag -a -m "rev-1" rev-1 &&
35 rev1=$(git rev-parse HEAD) &&
36 if test -z "$rev1"
37 then
38 echo "[OOPS] submodule git rev-parse returned nothing"
39 false
40 fi &&
41 cd .. &&
42 echo a >a &&
43 echo z >z &&
44 git add a init z &&
45 git-commit -m "super commit 1" &&
46 mv init .subrepo &&
47 GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/init.git
50 test_expect_success 'status should fail for unmapped paths' '
51 if git-submodule status
52 then
53 echo "[OOPS] submodule status succeeded"
54 false
55 elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init
56 then
57 echo "[OOPS] git config failed to update .gitmodules"
58 false
62 test_expect_success 'status should only print one line' '
63 lines=$(git-submodule status | wc -l) &&
64 test $lines = 1
67 test_expect_success 'status should initially be "missing"' '
68 git-submodule status | grep "^-$rev1"
71 test_expect_success 'init should register submodule url in .git/config' '
72 git-submodule init &&
73 url=$(git config submodule.example.url) &&
74 if test "$url" != "git://example.com/init.git"
75 then
76 echo "[OOPS] init succeeded but submodule url is wrong"
77 false
78 elif ! git config submodule.example.url ./.subrepo
79 then
80 echo "[OOPS] init succeeded but update of url failed"
81 false
85 test_expect_success 'update should fail when path is used by a file' '
86 echo "hello" >init &&
87 if git-submodule update
88 then
89 echo "[OOPS] update should have failed"
90 false
91 elif test "$(cat init)" != "hello"
92 then
93 echo "[OOPS] update failed but init file was molested"
94 false
95 else
96 rm init
100 test_expect_success 'update should fail when path is used by a nonempty directory' '
101 mkdir init &&
102 echo "hello" >init/a &&
103 if git-submodule update
104 then
105 echo "[OOPS] update should have failed"
106 false
107 elif test "$(cat init/a)" != "hello"
108 then
109 echo "[OOPS] update failed but init/a was molested"
110 false
111 else
112 rm init/a
116 test_expect_success 'update should work when path is an empty dir' '
117 rm -rf init &&
118 mkdir init &&
119 git-submodule update &&
120 head=$(cd init && git rev-parse HEAD) &&
121 if test -z "$head"
122 then
123 echo "[OOPS] Failed to obtain submodule head"
124 false
125 elif test "$head" != "$rev1"
126 then
127 echo "[OOPS] Submodule head is $head but should have been $rev1"
128 false
132 test_expect_success 'status should be "up-to-date" after update' '
133 git-submodule status | grep "^ $rev1"
136 test_expect_success 'status should be "modified" after submodule commit' '
137 cd init &&
138 echo b >b &&
139 git add b &&
140 git-commit -m "submodule commit 2" &&
141 rev2=$(git rev-parse HEAD) &&
142 cd .. &&
143 if test -z "$rev2"
144 then
145 echo "[OOPS] submodule git rev-parse returned nothing"
146 false
147 fi &&
148 git-submodule status | grep "^+$rev2"
151 test_expect_success 'the --cached sha1 should be rev1' '
152 git-submodule --cached status | grep "^+$rev1"
155 test_expect_success 'git diff should report the SHA1 of the new submodule commit' '
156 git-diff | grep "^+Subproject commit $rev2"
159 test_expect_success 'update should checkout rev1' '
160 git-submodule update init &&
161 head=$(cd init && git rev-parse HEAD) &&
162 if test -z "$head"
163 then
164 echo "[OOPS] submodule git rev-parse returned nothing"
165 false
166 elif test "$head" != "$rev1"
167 then
168 echo "[OOPS] init did not checkout correct head"
169 false
173 test_expect_success 'status should be "up-to-date" after update' '
174 git-submodule status | grep "^ $rev1"
177 test_expect_success 'checkout superproject with subproject already present' '
178 git-checkout initial &&
179 git-checkout master
182 test_expect_success 'apply submodule diff' '
183 git branch second &&
185 cd init &&
186 echo s >s &&
187 git add s &&
188 git commit -m "change subproject"
189 ) &&
190 git update-index --add init &&
191 git-commit -m "change init" &&
192 git-format-patch -1 --stdout >P.diff &&
193 git checkout second &&
194 git apply --index P.diff &&
195 D=$(git diff --cached master) &&
196 test -z "$D"
199 test_expect_success 'update --init' '
201 mv init init2 &&
202 git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
203 git config --remove-section submodule.example
204 git submodule update init > update.out &&
205 grep "not initialized" update.out &&
206 test ! -d init/.git &&
207 git submodule update --init init &&
208 test -d init/.git
212 test_done