1#!/bin/sh
2# Copyright (c) 2010, Jens Lehmann
3
4test_description='Recursive "git fetch" for submodules'
5
6. ./test-lib.sh
7
8pwd=$(pwd)
9
10add_upstream_commit() {
11 (
12 cd submodule &&
13 head1=$(git rev-parse --short HEAD) &&
14 echo new >> subfile &&
15 test_tick &&
16 git add subfile &&
17 git commit -m new subfile &&
18 head2=$(git rev-parse --short HEAD) &&
19 echo "From $pwd/submodule" > ../expect.err &&
20 echo " $head1..$head2 master -> origin/master" >> ../expect.err
21 ) &&
22 (
23 cd deepsubmodule &&
24 head1=$(git rev-parse --short HEAD) &&
25 echo new >> deepsubfile &&
26 test_tick &&
27 git add deepsubfile &&
28 git commit -m new deepsubfile &&
29 head2=$(git rev-parse --short HEAD) &&
30 echo "From $pwd/deepsubmodule" >> ../expect.err &&
31 echo " $head1..$head2 master -> origin/master" >> ../expect.err
32 )
33}
34
35test_expect_success setup '
36 mkdir deepsubmodule &&
37 (
38 cd deepsubmodule &&
39 git init &&
40 echo deepsubcontent > deepsubfile &&
41 git add deepsubfile &&
42 git commit -m new deepsubfile
43 ) &&
44 mkdir submodule &&
45 (
46 cd submodule &&
47 git init &&
48 echo subcontent > subfile &&
49 git add subfile &&
50 git submodule add "$pwd/deepsubmodule" deepsubmodule &&
51 git commit -a -m new
52 ) &&
53 git submodule add "$pwd/submodule" submodule &&
54 git commit -am initial &&
55 git clone . downstream &&
56 (
57 cd downstream &&
58 git submodule update --init --recursive
59 ) &&
60 echo "Fetching submodule submodule" > expect.out &&
61 echo "Fetching submodule submodule/deepsubmodule" >> expect.out
62'
63
64test_expect_success "fetch --recurse-submodules recurses into submodules" '
65 add_upstream_commit &&
66 (
67 cd downstream &&
68 git fetch --recurse-submodules >../actual.out 2>../actual.err
69 )
70'
71
72test_expect_success C_LOCALE_OUTPUT "fetch --recurse-submodules recurses into submodules: output" '
73 test_cmp expect.out actual.out &&
74 test_cmp expect.err actual.err
75'
76
77test_expect_success "fetch alone only fetches superproject" '
78 add_upstream_commit &&
79 (
80 cd downstream &&
81 git fetch >../actual.out 2>../actual.err
82 ) &&
83 ! test -s actual.out &&
84 ! test -s actual.err
85'
86
87test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
88 (
89 cd downstream &&
90 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
91 ) &&
92 ! test -s actual.out &&
93 ! test -s actual.err
94'
95
96test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
97 (
98 cd downstream &&
99 git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
100 git fetch >../actual.out 2>../actual.err
101 )
102'
103
104test_expect_success C_LOCALE_OUTPUT "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
105 test_cmp expect.out actual.out &&
106 test_cmp expect.err actual.err
107'
108
109test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
110 add_upstream_commit &&
111 (
112 cd downstream &&
113 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
114 ) &&
115 ! test -s actual.out &&
116 ! test -s actual.err
117'
118
119test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
120 (
121 cd downstream &&
122 git config submodule.submodule.fetchRecurseSubmodules false &&
123 git fetch >../actual.out 2>../actual.err
124 ) &&
125 ! test -s actual.out &&
126 ! test -s actual.err
127'
128
129test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
130 (
131 cd downstream &&
132 git fetch --recurse-submodules >../actual.out 2>../actual.err &&
133 git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules &&
134 git config --unset submodule.submodule.fetchRecurseSubmodules
135 )
136'
137
138test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config: output" '
139 test_cmp expect.out actual.out &&
140 test_cmp expect.err actual.err
141'
142
143test_expect_success "--quiet propagates to submodules" '
144 (
145 cd downstream &&
146 git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
147 ) &&
148 ! test -s actual.out &&
149 ! test -s actual.err
150'
151
152test_expect_success "--dry-run propagates to submodules" '
153 add_upstream_commit &&
154 (
155 cd downstream &&
156 git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
157 )
158'
159
160test_expect_success C_LOCALE_OUTPUT "--dry-run propagates to submodules: output" '
161 test_cmp expect.out actual.out &&
162 test_cmp expect.err actual.err
163'
164
165test_expect_success "Without --dry-run propagates to submodules" '
166 (
167 cd downstream &&
168 git fetch --recurse-submodules >../actual.out 2>../actual.err
169 )
170'
171
172test_expect_success C_LOCALE_OUTPUT "Without --dry-run propagates to submodules: output" '
173 test_cmp expect.out actual.out &&
174 test_cmp expect.err actual.err
175'
176
177test_expect_success "recurseSubmodules=true propagates into submodules" '
178 add_upstream_commit &&
179 (
180 cd downstream &&
181 git config fetch.recurseSubmodules true
182 git fetch >../actual.out 2>../actual.err
183 )
184'
185
186test_expect_success C_LOCALE_OUTPUT "recurseSubmodules=true propagates into submodules: output" '
187 test_cmp expect.out actual.out &&
188 test_cmp expect.err actual.err
189'
190
191test_expect_success "--recurse-submodules overrides config in submodule" '
192 add_upstream_commit &&
193 (
194 cd downstream &&
195 (
196 cd submodule &&
197 git config fetch.recurseSubmodules false
198 ) &&
199 git fetch --recurse-submodules >../actual.out 2>../actual.err
200 )
201'
202
203test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides config in submodule: output" '
204 test_cmp expect.out actual.out &&
205 test_cmp expect.err actual.err
206'
207
208test_expect_success "--no-recurse-submodules overrides config setting" '
209 add_upstream_commit &&
210 (
211 cd downstream &&
212 git config fetch.recurseSubmodules true
213 git fetch --no-recurse-submodules >../actual.out 2>../actual.err
214 ) &&
215 ! test -s actual.out &&
216 ! test -s actual.err
217'
218
219test_done