fix diff-tree --stdin documentation
[git/git-p4.git] / t / t7401-submodule-summary.sh
blobbf12dbdeef6e307850a91eb6be5ebe537b2de0c8
1 #!/bin/sh
3 # Copyright (c) 2008 Ping Yin
6 test_description='Summary support for submodules
8 This test tries to verify the sanity of summary subcommand of git-submodule.
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"
27 commit_file () {
28 test_tick &&
29 git commit "$@" -m "Commit $*" >/dev/null
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
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
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
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
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
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
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):
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
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
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:
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
174 test_expect_success 'path filter' "
175 git submodule summary sm2 >actual &&
176 diff actual - <<-EOF
177 * sm2 0000000...$head7 (2):
178 > Add foo9
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
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
208 test_done