]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7400-submodule-basic.sh
git-submodule: move cloning into a separate function
[thirdparty/git.git] / t / t7400-submodule-basic.sh
CommitLineData
88961ef2
LH
1#!/bin/sh
2#
3# Copyright (c) 2007 Lars Hjemli
4#
5
6test_description='Basic porcelain support for submodules
7
8This test tries to verify basic sanity of the init, update and status
9subcommands of git-submodule.
10'
11
12. ./test-lib.sh
13
14#
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'
22#
23test_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 ./.subrepo
44'
45
46test_expect_success 'status should only print one line' '
47 lines=$(git-submodule status | wc -l) &&
48 test $lines = 1
49'
50
51test_expect_success 'status should initially be "missing"' '
52 git-submodule status | grep "^-$rev1"
53'
54
55test_expect_success 'init should fail when path is used by a file' '
56 echo "hello" >lib &&
57 if git-submodule init
58 then
59 echo "[OOPS] init should have failed"
60 false
61 elif test -f lib && test "$(cat lib)" != "hello"
62 then
63 echo "[OOPS] init failed but lib file was molested"
64 false
65 else
66 rm lib
67 fi
68'
69
70test_expect_success 'init should fail when path is used by a nonempty directory' '
71 mkdir lib &&
72 echo "hello" >lib/a &&
73 if git-submodule init
74 then
75 echo "[OOPS] init should have failed"
76 false
77 elif test "$(cat lib/a)" != "hello"
78 then
79 echo "[OOPS] init failed but lib/a was molested"
80 false
81 else
82 rm lib/a
83 fi
84'
85
86test_expect_success 'init should work when path is an empty dir' '
87 rm -rf lib &&
88 mkdir lib &&
89 git-submodule init &&
90 head=$(cd lib && git-rev-parse HEAD) &&
91 if test -z "$head"
92 then
93 echo "[OOPS] Failed to obtain submodule head"
94 false
95 elif test "$head" != "$rev1"
96 then
97 echo "[OOPS] Submodule head is $head but should have been $rev1"
98 false
99 fi
100'
101
102test_expect_success 'status should be "up-to-date" after init' '
103 git-submodule status | grep "^ $rev1"
104'
105
106test_expect_success 'status should be "modified" after submodule commit' '
107 cd lib &&
108 echo b >b &&
109 git-add b &&
110 git-commit -m "submodule commit 2" &&
111 rev2=$(git-rev-parse HEAD) &&
112 cd .. &&
113 if test -z "$rev2"
114 then
115 echo "[OOPS] submodule git-rev-parse returned nothing"
116 false
117 fi &&
118 git-submodule status | grep "^+$rev2"
119'
120
121test_expect_success 'the --cached sha1 should be rev1' '
122 git-submodule --cached status | grep "^+$rev1"
123'
124
125test_expect_success 'update should checkout rev1' '
126 git-submodule update &&
127 head=$(cd lib && git-rev-parse HEAD) &&
128 if test -z "$head"
129 then
130 echo "[OOPS] submodule git-rev-parse returned nothing"
131 false
132 elif test "$head" != "$rev1"
133 then
134 echo "[OOPS] init did not checkout correct head"
135 false
136 fi
137'
138
139test_expect_success 'status should be "up-to-date" after update' '
140 git-submodule status | grep "^ $rev1"
141'
142
143test_done