Mark disused commit walkers officially deprecated.
[git/jrn.git] / t / t7400-submodule-basic.sh
blob5e91db64e95d25049e298f37a2dadb436af8c8d0
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 lib
17 # -add a couple of files
18 # -add directory lib to 'superproject', this creates a DIRLINK entry
19 # -add a couple of regular files to enable testing of submodule filtering
20 # -mv lib subrepo
21 # -add an entry to .gitmodules for submodule 'example'
23 test_expect_success 'Prepare submodule testing' '
24 mkdir lib &&
25 cd lib &&
26 git init &&
27 echo a >a &&
28 git add a &&
29 git-commit -m "submodule commit 1" &&
30 git-tag -a -m "rev-1" rev-1 &&
31 rev1=$(git rev-parse HEAD) &&
32 if test -z "$rev1"
33 then
34 echo "[OOPS] submodule git rev-parse returned nothing"
35 false
36 fi &&
37 cd .. &&
38 echo a >a &&
39 echo z >z &&
40 git add a lib z &&
41 git-commit -m "super commit 1" &&
42 mv lib .subrepo &&
43 GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/lib.git
46 test_expect_success 'status should fail for unmapped paths' '
47 if git-submodule status
48 then
49 echo "[OOPS] submodule status succeeded"
50 false
51 elif ! GIT_CONFIG=.gitmodules git config submodule.example.path lib
52 then
53 echo "[OOPS] git config failed to update .gitmodules"
54 false
58 test_expect_success 'status should only print one line' '
59 lines=$(git-submodule status | wc -l) &&
60 test $lines = 1
63 test_expect_success 'status should initially be "missing"' '
64 git-submodule status | grep "^-$rev1"
67 test_expect_success 'init should register submodule url in .git/config' '
68 git-submodule init &&
69 url=$(git config submodule.example.url) &&
70 if test "$url" != "git://example.com/lib.git"
71 then
72 echo "[OOPS] init succeeded but submodule url is wrong"
73 false
74 elif ! git config submodule.example.url ./.subrepo
75 then
76 echo "[OOPS] init succeeded but update of url failed"
77 false
81 test_expect_success 'update should fail when path is used by a file' '
82 echo "hello" >lib &&
83 if git-submodule update
84 then
85 echo "[OOPS] update should have failed"
86 false
87 elif test "$(cat lib)" != "hello"
88 then
89 echo "[OOPS] update failed but lib file was molested"
90 false
91 else
92 rm lib
96 test_expect_success 'update should fail when path is used by a nonempty directory' '
97 mkdir lib &&
98 echo "hello" >lib/a &&
99 if git-submodule update
100 then
101 echo "[OOPS] update should have failed"
102 false
103 elif test "$(cat lib/a)" != "hello"
104 then
105 echo "[OOPS] update failed but lib/a was molested"
106 false
107 else
108 rm lib/a
112 test_expect_success 'update should work when path is an empty dir' '
113 rm -rf lib &&
114 mkdir lib &&
115 git-submodule update &&
116 head=$(cd lib && git rev-parse HEAD) &&
117 if test -z "$head"
118 then
119 echo "[OOPS] Failed to obtain submodule head"
120 false
121 elif test "$head" != "$rev1"
122 then
123 echo "[OOPS] Submodule head is $head but should have been $rev1"
124 false
128 test_expect_success 'status should be "up-to-date" after update' '
129 git-submodule status | grep "^ $rev1"
132 test_expect_success 'status should be "modified" after submodule commit' '
133 cd lib &&
134 echo b >b &&
135 git add b &&
136 git-commit -m "submodule commit 2" &&
137 rev2=$(git rev-parse HEAD) &&
138 cd .. &&
139 if test -z "$rev2"
140 then
141 echo "[OOPS] submodule git rev-parse returned nothing"
142 false
143 fi &&
144 git-submodule status | grep "^+$rev2"
147 test_expect_success 'the --cached sha1 should be rev1' '
148 git-submodule --cached status | grep "^+$rev1"
151 test_expect_success 'update should checkout rev1' '
152 git-submodule update &&
153 head=$(cd lib && git rev-parse HEAD) &&
154 if test -z "$head"
155 then
156 echo "[OOPS] submodule git rev-parse returned nothing"
157 false
158 elif test "$head" != "$rev1"
159 then
160 echo "[OOPS] init did not checkout correct head"
161 false
165 test_expect_success 'status should be "up-to-date" after update' '
166 git-submodule status | grep "^ $rev1"
169 test_done