Code

Merge 'build-in git-mktree'
[git.git] / t / t7401-submodule-summary.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Ping Yin
4 #
6 test_description='Summary support for submodules
8 This test tries to verify the sanity of summary subcommand of git submodule.
9 '
11 . ./test-lib.sh
13 add_file () {
14         sm=$1
15         shift
16         owd=$(pwd)
17         cd "$sm"
18         for name; do
19                 echo "$name" > "$name" &&
20                 git add "$name" &&
21                 test_tick &&
22                 git commit -m "Add $name"
23         done >/dev/null
24         git rev-parse --verify HEAD | cut -c1-7
25         cd "$owd"
26 }
27 commit_file () {
28         test_tick &&
29         git commit "$@" -m "Commit $*" >/dev/null
30 }
32 test_create_repo sm1 &&
33 add_file . foo >/dev/null
35 head1=$(add_file sm1 foo1 foo2)
37 test_expect_success 'added submodule' "
38         git add sm1 &&
39         git submodule summary >actual &&
40         diff actual - <<-EOF
41 * sm1 0000000...$head1 (2):
42   > Add foo2
44 EOF
45 "
47 commit_file sm1 &&
48 head2=$(add_file sm1 foo3)
50 test_expect_success 'modified submodule(forward)' "
51         git submodule summary >actual &&
52         diff actual - <<-EOF
53 * sm1 $head1...$head2 (1):
54   > Add foo3
56 EOF
57 "
59 commit_file sm1 &&
60 cd sm1 &&
61 git reset --hard HEAD~2 >/dev/null &&
62 head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
63 cd ..
65 test_expect_success 'modified submodule(backward)' "
66     git submodule summary >actual &&
67     diff actual - <<-EOF
68 * sm1 $head2...$head3 (2):
69   < Add foo3
70   < Add foo2
72 EOF
73 "
75 head4=$(add_file sm1 foo4 foo5) &&
76 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
77 test_expect_success 'modified submodule(backward and forward)' "
78     git submodule summary >actual &&
79     diff actual - <<-EOF
80 * sm1 $head2...$head4 (4):
81   > Add foo5
82   > Add foo4
83   < Add foo3
84   < Add foo2
86 EOF
87 "
89 test_expect_success '--summary-limit' "
90     git submodule summary -n 3 >actual &&
91     diff actual - <<-EOF
92 * sm1 $head2...$head4 (4):
93   > Add foo5
94   > Add foo4
95   < Add foo3
97 EOF
98 "
100 commit_file sm1 &&
101 mv sm1 sm1-bak &&
102 echo sm1 >sm1 &&
103 head5=$(git hash-object sm1 | cut -c1-7) &&
104 git add sm1 &&
105 rm -f sm1 &&
106 mv sm1-bak sm1
108 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
109     git submodule summary --cached >actual &&
110     diff actual - <<-EOF
111 * sm1 $head4(submodule)->$head5(blob) (3):
112   < Add foo5
114 EOF
117 rm -rf sm1 &&
118 git checkout-index sm1
119 test_expect_success 'typechanged submodule(submodule->blob)' "
120     git submodule summary >actual &&
121     diff actual - <<-EOF
122 * sm1 $head4(submodule)->$head5(blob):
124 EOF
127 rm -f sm1 &&
128 test_create_repo sm1 &&
129 head6=$(add_file sm1 foo6 foo7)
130 test_expect_success 'nonexistent commit' "
131     git submodule summary >actual &&
132     diff actual - <<-EOF
133 * sm1 $head4...$head6:
134   Warn: sm1 doesn't contain commit $head4_full
136 EOF
139 commit_file
140 test_expect_success 'typechanged submodule(blob->submodule)' "
141     git submodule summary >actual &&
142     diff actual - <<-EOF
143 * sm1 $head5(blob)->$head6(submodule) (2):
144   > Add foo7
146 EOF
149 commit_file sm1 &&
150 rm -rf sm1
151 test_expect_success 'deleted submodule' "
152     git submodule summary >actual &&
153     diff actual - <<-EOF
154 * sm1 $head6...0000000:
156 EOF
159 test_create_repo sm2 &&
160 head7=$(add_file sm2 foo8 foo9) &&
161 git add sm2
163 test_expect_success 'multiple submodules' "
164     git submodule summary >actual &&
165     diff actual - <<-EOF
166 * sm1 $head6...0000000:
168 * sm2 0000000...$head7 (2):
169   > Add foo9
171 EOF
174 test_expect_success 'path filter' "
175     git submodule summary sm2 >actual &&
176     diff actual - <<-EOF
177 * sm2 0000000...$head7 (2):
178   > Add foo9
180 EOF
183 commit_file sm2
184 test_expect_success 'given commit' "
185     git submodule summary HEAD^ >actual &&
186     diff actual - <<-EOF
187 * sm1 $head6...0000000:
189 * sm2 0000000...$head7 (2):
190   > Add foo9
192 EOF
195 test_expect_success '--for-status' "
196     git submodule summary --for-status HEAD^ >actual &&
197     test_cmp actual - <<EOF
198 # Modified submodules:
200 # * sm1 $head6...0000000:
202 # * sm2 0000000...$head7 (2):
203 #   > Add foo9
205 EOF
208 test_done