pp_header(): work around possible memory corruption
[git/kirr.git] / t / t7400-submodule-basic.sh
blob3940433b8f59196eff06dd24be24c9f54e7254ac
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 path 'lib'
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 module.lib.url git://example.com/lib.git
46 test_expect_success 'status should only print one line' '
47 lines=$(git-submodule status | wc -l) &&
48 test $lines = 1
51 test_expect_success 'status should initially be "missing"' '
52 git-submodule status | grep "^-$rev1"
55 test_expect_success 'init should register submodule url in .git/config' '
56 git-submodule init &&
57 url=$(git-config submodule.lib.url) &&
58 if test "$url" != "git://example.com/lib.git"
59 then
60 echo "[OOPS] init succeeded but submodule url is wrong"
61 false
62 elif ! git-config submodule.lib.url ./.subrepo
63 then
64 echo "[OOPS] init succeeded but update of url failed"
65 false
69 test_expect_success 'update should fail when path is used by a file' '
70 echo "hello" >lib &&
71 if git-submodule update
72 then
73 echo "[OOPS] update should have failed"
74 false
75 elif test -f lib && test "$(cat lib)" != "hello"
76 then
77 echo "[OOPS] update failed but lib file was molested"
78 false
79 else
80 rm lib
84 test_expect_success 'update should fail when path is used by a nonempty directory' '
85 mkdir lib &&
86 echo "hello" >lib/a &&
87 if git-submodule update
88 then
89 echo "[OOPS] update should have failed"
90 false
91 elif test "$(cat lib/a)" != "hello"
92 then
93 echo "[OOPS] update failed but lib/a was molested"
94 false
95 else
96 rm lib/a
100 test_expect_success 'update should work when path is an empty dir' '
101 rm -rf lib &&
102 mkdir lib &&
103 git-submodule update &&
104 head=$(cd lib && git-rev-parse HEAD) &&
105 if test -z "$head"
106 then
107 echo "[OOPS] Failed to obtain submodule head"
108 false
109 elif test "$head" != "$rev1"
110 then
111 echo "[OOPS] Submodule head is $head but should have been $rev1"
112 false
116 test_expect_success 'status should be "up-to-date" after update' '
117 git-submodule status | grep "^ $rev1"
120 test_expect_success 'status should be "modified" after submodule commit' '
121 cd lib &&
122 echo b >b &&
123 git-add b &&
124 git-commit -m "submodule commit 2" &&
125 rev2=$(git-rev-parse HEAD) &&
126 cd .. &&
127 if test -z "$rev2"
128 then
129 echo "[OOPS] submodule git-rev-parse returned nothing"
130 false
131 fi &&
132 git-submodule status | grep "^+$rev2"
135 test_expect_success 'the --cached sha1 should be rev1' '
136 git-submodule --cached status | grep "^+$rev1"
139 test_expect_success 'update should checkout rev1' '
140 git-submodule update &&
141 head=$(cd lib && git-rev-parse HEAD) &&
142 if test -z "$head"
143 then
144 echo "[OOPS] submodule git-rev-parse returned nothing"
145 false
146 elif test "$head" != "$rev1"
147 then
148 echo "[OOPS] init did not checkout correct head"
149 false
153 test_expect_success 'status should be "up-to-date" after update' '
154 git-submodule status | grep "^ $rev1"
157 test_done