Skip to content

Commit dfbe16f

Browse files
committed
Added test scenario for using branch@commit
It does the following: 1. Clone default test repos foo and bar 2. Create a new branch bar1 in bar 3. In bar create three additional commits in bar1 4. Checkout default branch in bar (to allow for later push) 5. In foo subrepo clone of bar1@commit1 from bar 6. Test clone results 7. In foo subrepo pull of bar1@commit2 from bar 8. Test pull results 9. Make additional change in foo/bar 10. In foo subrepo push bar and test result (push fails) 11. In foo force subrepo clone bar@commit3 (last commit in bar1) 12. Re-make additional change in foo/bar 13. In foo subrepo push bar and test result (push success) 13. In foo subrepo pull bar1 from bar and test result (up to date) 14. In foo subrepo pull bar1@commit2 (fails - old commit) 15. In foo subrepo clone bar1@commit2 (fails - subrepo exists)
1 parent 9e33d47 commit dfbe16f

File tree

1 file changed

+368
-0
lines changed

1 file changed

+368
-0
lines changed

test/use-branch-at-commit.t

Lines changed: 368 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,368 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
source test/setup
6+
7+
use Test::More
8+
9+
clone-foo-and-bar
10+
11+
# Test that the repos look ok:
12+
{
13+
test-exists \
14+
"$OWNER/foo/.git/" \
15+
"$OWNER/foo/Foo" \
16+
"!$OWNER/foo/bar/" \
17+
"$OWNER/bar/.git/" \
18+
"$OWNER/bar/Bar"
19+
}
20+
21+
# Make a new branch bar1 in bar
22+
(
23+
cd $OWNER/bar
24+
git checkout -b bar1
25+
) &> /dev/null || die
26+
27+
# check the new bar1 branch:
28+
{
29+
is "$(
30+
cd "$OWNER/bar"
31+
git branch | grep "^*"
32+
)" \
33+
"* bar1" \
34+
'bar: The repo branch is correct'
35+
}
36+
37+
# Make a few new commits in a new branch bar1
38+
(
39+
cd $OWNER/bar
40+
echo "Added first change to Bar" >> Bar
41+
git add Bar
42+
git commit -m"Added first commit to Bar"
43+
) &> /dev/null || die
44+
45+
{
46+
cd $OWNER/bar
47+
bar_commit1=$(git rev-parse HEAD)
48+
is "$(
49+
cd "$OWNER/bar"
50+
git log -1 --oneline | sed -e 's/ .*//g'
51+
)" \
52+
"${bar_commit1:0:7}" \
53+
'bar: The first added commit is correct'
54+
}
55+
56+
(
57+
cd $OWNER/bar
58+
echo "Added second change to Bar" >> Bar
59+
git add Bar
60+
git commit -m"Added second commit to Bar"
61+
) &> /dev/null || die
62+
63+
{
64+
cd $OWNER/bar
65+
bar_commit2=$(git rev-parse HEAD)
66+
is "$(
67+
cd "$OWNER/bar"
68+
git log -1 --oneline | sed -e 's/ .*//g'
69+
)" \
70+
"${bar_commit2:0:7}" \
71+
'bar: The second added commit is correct'
72+
}
73+
74+
(
75+
cd $OWNER/bar
76+
echo "Added third change to Bar" >> Bar
77+
git add Bar
78+
git commit -m"Added third commit to Bar"
79+
) &> /dev/null || die
80+
81+
{
82+
cd $OWNER/bar
83+
bar_commit3=$(git rev-parse HEAD)
84+
is "$(
85+
cd "$OWNER/bar"
86+
git log -1 --oneline | sed -e 's/ .*//g'
87+
)" \
88+
"${bar_commit3:0:7}" \
89+
'bar: The third added commit is correct'
90+
}
91+
92+
# Checkout default branch in bar
93+
(
94+
cd $OWNER/bar
95+
git checkout ${DEFAULTBRANCH}
96+
) &> /dev/null || die
97+
98+
# check the default branch:
99+
{
100+
is "$(
101+
cd "$OWNER/bar"
102+
git branch | grep "^*"
103+
)" \
104+
"* ${DEFAULTBRANCH}" \
105+
'bar: The repo branch is correct'
106+
}
107+
108+
# Do the subrepo clone branch@commit1 and test the output:
109+
{
110+
clone_output=$(
111+
cd "$OWNER/foo"
112+
git subrepo clone -b bar1@${bar_commit1:0:8} "$OWNER/bar"
113+
)
114+
115+
# Check output is correct:
116+
is "$clone_output" \
117+
"Subrepo '$OWNER/bar' (bar1@${bar_commit1}) cloned into 'bar'." \
118+
'subrepo clone command output is correct'
119+
120+
is "$(
121+
cd "$OWNER/foo"
122+
git remote -v | grep subrepo/bar
123+
)" \
124+
"" \
125+
'No remotes created'
126+
}
127+
128+
# Check that subrepo files look ok:
129+
gitrepo=$OWNER/foo/bar/.gitrepo
130+
{
131+
test-exists \
132+
"$OWNER/foo/bar/" \
133+
"$OWNER/foo/bar/Bar" \
134+
"$gitrepo"
135+
}
136+
137+
# Test foo/bar/.gitrepo file contents:
138+
{
139+
foo_clone_commit=$(cd "$OWNER/foo"; git rev-parse HEAD^)
140+
test-gitrepo-comment-block
141+
test-gitrepo-field "remote" "$OWNER/bar"
142+
test-gitrepo-field "branch" "bar1"
143+
test-gitrepo-field "commit" "$bar_commit1"
144+
test-gitrepo-field "parent" "$foo_clone_commit"
145+
test-gitrepo-field "cmdver" "$(git subrepo --version)"
146+
}
147+
148+
# Make sure status is clean:
149+
{
150+
git_status=$(
151+
cd "$OWNER/foo"
152+
git status -s
153+
)
154+
155+
is "$git_status" \
156+
"" \
157+
'status is clean'
158+
}
159+
160+
# Do the subrepo pull branch@commit2 and test the output:
161+
{
162+
pull_output=$(
163+
cd "$OWNER/foo"
164+
git subrepo pull -b bar1@${bar_commit2:0:8} bar
165+
)
166+
167+
# Check output is correct:
168+
is "$pull_output" \
169+
"Subrepo 'bar' pulled from '$OWNER/bar' (bar1@${bar_commit2})." \
170+
'subrepo pull command output is correct'
171+
172+
is "$(
173+
cd "$OWNER/foo"
174+
git remote -v | grep subrepo/bar
175+
)" \
176+
"" \
177+
'No remotes created'
178+
}
179+
180+
# Check that subrepo files look ok:
181+
gitrepo=$OWNER/foo/bar/.gitrepo
182+
{
183+
test-exists \
184+
"$OWNER/foo/bar/" \
185+
"$OWNER/foo/bar/Bar" \
186+
"$gitrepo"
187+
}
188+
189+
# Test foo/bar/.gitrepo file contents:
190+
{
191+
foo_clone_commit=$(cd "$OWNER/foo"; git rev-parse HEAD^)
192+
test-gitrepo-comment-block
193+
test-gitrepo-field "remote" "$OWNER/bar"
194+
test-gitrepo-field "branch" "bar1"
195+
test-gitrepo-field "commit" "$bar_commit2"
196+
test-gitrepo-field "parent" "$foo_clone_commit"
197+
test-gitrepo-field "cmdver" "$(git subrepo --version)"
198+
}
199+
200+
# Make sure status is clean:
201+
{
202+
git_status=$(
203+
cd "$OWNER/foo"
204+
git status -s
205+
)
206+
207+
is "$git_status" \
208+
"" \
209+
'status is clean'
210+
}
211+
212+
# Make additional change in foo/bar
213+
(
214+
cd $OWNER/foo
215+
echo "Added first change to foo/bar/Bar" >> bar/Bar
216+
git add bar/Bar
217+
git commit -m"Added first commit to foo/bar/Bar"
218+
#foo_commit1=$(git rev-parse HEAD)
219+
) &> /dev/null || die
220+
221+
{
222+
cd $OWNER/foo
223+
foo_commit1=$(git rev-parse HEAD)
224+
is "$(
225+
cd "$OWNER/foo"
226+
git log -1 --oneline | sed -e 's/ .*//g'
227+
)" \
228+
"${foo_commit1:0:7}" \
229+
'foo: The first added commit is correct'
230+
}
231+
232+
# Do the subrepo push and test output
233+
{
234+
message=$(
235+
cd "$OWNER/foo"
236+
git subrepo push bar 2>&1 || true
237+
)
238+
239+
is "$message" "git-subrepo: There are new changes upstream, you need to pull first." \
240+
'Subrepo push command output is correct'
241+
}
242+
243+
# Do the subrepo forced clone branch@commit3and test the output:
244+
{
245+
clone_output=$(
246+
cd "$OWNER/foo"
247+
git subrepo clone -f -b bar1@${bar_commit3:0:8} "$OWNER/bar"
248+
)
249+
250+
# Check output is correct:
251+
is "$clone_output" \
252+
"Subrepo '$OWNER/bar' (bar1@${bar_commit3}) recloned into 'bar'." \
253+
'subrepo clone command output is correct'
254+
255+
is "$(
256+
cd "$OWNER/foo"
257+
git remote -v | grep subrepo/bar
258+
)" \
259+
"" \
260+
'No remotes created'
261+
}
262+
263+
# Check that subrepo files look ok:
264+
gitrepo=$OWNER/foo/bar/.gitrepo
265+
{
266+
test-exists \
267+
"$OWNER/foo/bar/" \
268+
"$OWNER/foo/bar/Bar" \
269+
"$gitrepo"
270+
}
271+
272+
# Test foo/bar/.gitrepo file contents:
273+
{
274+
foo_clone_commit=$(cd "$OWNER/foo"; git rev-parse HEAD^)
275+
test-gitrepo-comment-block
276+
test-gitrepo-field "remote" "$OWNER/bar"
277+
test-gitrepo-field "branch" "bar1"
278+
test-gitrepo-field "commit" "$bar_commit3"
279+
test-gitrepo-field "parent" "$foo_clone_commit"
280+
test-gitrepo-field "cmdver" "$(git subrepo --version)"
281+
}
282+
283+
# Make sure status is clean:
284+
{
285+
git_status=$(
286+
cd "$OWNER/foo"
287+
git status -s
288+
)
289+
290+
is "$git_status" \
291+
"" \
292+
'status is clean'
293+
}
294+
295+
# Make additional change in foo/bar
296+
(
297+
cd $OWNER/foo
298+
echo "Added first change to foo/bar/Bar" >> bar/Bar
299+
git add bar/Bar
300+
git commit -m"Added first commit to foo/bar/Bar"
301+
#foo_commit1=$(git rev-parse HEAD)
302+
) &> /dev/null || die
303+
304+
{
305+
cd $OWNER/foo
306+
foo_commit1=$(git rev-parse HEAD)
307+
is "$(
308+
cd "$OWNER/foo"
309+
git log -1 --oneline | sed -e 's/ .*//g'
310+
)" \
311+
"${foo_commit1:0:7}" \
312+
'foo: The first added commit is correct'
313+
}
314+
315+
# Do the subrepo push and test output
316+
{
317+
message=$(
318+
cd "$OWNER/foo"
319+
git subrepo push bar 2>&1 || true
320+
)
321+
322+
is "$message" \
323+
"Subrepo 'bar' pushed to '$OWNER/bar' (bar1)." \
324+
'Subrepo push command output is correct'
325+
}
326+
327+
# Do the subrepo pull branch and test the output:
328+
{
329+
pull_output=$(
330+
cd "$OWNER/foo"
331+
git subrepo pull -b bar1 bar
332+
)
333+
334+
# Check output is correct:
335+
is "$pull_output" \
336+
"Subrepo 'bar' is up to date." \
337+
'subrepo pull command output is correct'
338+
}
339+
340+
# Do the subrepo pull branch@commit2 and test the output:
341+
{
342+
pull_output=$(
343+
cd "$OWNER/foo"
344+
git subrepo pull -b bar1@${bar_commit2:0:8} bar 2>&1 | sed -e 's/not contain.*/not contain/' || true
345+
)
346+
347+
# Check output is correct:
348+
is "$pull_output" \
349+
"git-subrepo: Local repository does not contain" \
350+
'subrepo pull command output is correct'
351+
}
352+
353+
# Do the subrepo clone branch@commit2 and test the output:
354+
{
355+
clone_output=$(
356+
cd "$OWNER/foo"
357+
git subrepo clone -b bar1@${bar_commit2:0:8} "$OWNER/bar" 2>&1 || true
358+
)
359+
360+
# Check output is correct:
361+
is "$clone_output" \
362+
"git-subrepo: The subdir 'bar' exists and is not empty." \
363+
'subrepo clone command output is correct'
364+
}
365+
366+
done_testing
367+
368+
teardown

0 commit comments

Comments
 (0)