Skip to content

Commit af04cf8

Browse files
committed
Test cases for sparse checkout
The new t7000-sparse-checkout.sh test script exercises various StGit commands in the context of a sparse checkout worktree. Relates-to: #195
1 parent f7495a2 commit af04cf8

File tree

1 file changed

+197
-0
lines changed

1 file changed

+197
-0
lines changed

t/t7000-sparse-checkout.sh

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
#!/bin/sh
2+
3+
test_description='Test StGit with sparse checkout'
4+
5+
. ./test-lib.sh
6+
7+
cat >> .git/info/exclude <<EOF
8+
/*expected
9+
/*out
10+
EOF
11+
12+
test_expect_success 'Setup repository' '
13+
mkdir -p a b/0 b/1 c d/0 d/1 &&
14+
echo alpha > a/alpha.txt &&
15+
echo beta0 > b/0/beta.txt &&
16+
echo beta1 > b/1/beta.txt &&
17+
echo gamma > c/gamma.txt &&
18+
echo delta > d/0/delta.txt &&
19+
echo delta > d/1/delta.txt &&
20+
echo hello > top.txt &&
21+
git add a b c d top.txt &&
22+
git commit -m "Initial commit"
23+
'
24+
25+
cone_intact() {
26+
cone_files_present && outside_cone_files_absent
27+
}
28+
29+
cone_files_present() {
30+
test_path_is_file a/alpha.txt &&
31+
test_path_is_file b/1/beta.txt &&
32+
test_path_is_file top.txt
33+
}
34+
35+
outside_cone_files_absent() {
36+
test_path_is_missing b/0 &&
37+
test_path_is_missing c &&
38+
test_path_is_missing d
39+
}
40+
41+
clean_status() {
42+
stg status >status-out &&
43+
test_line_count = 0 status-out
44+
}
45+
46+
test_expect_success 'Setup sparse checkout' '
47+
git sparse-checkout set a b/1 &&
48+
cone_intact
49+
'
50+
51+
test_expect_success 'Initialize StGit' '
52+
stg init &&
53+
cone_intact
54+
'
55+
56+
cat > files-expected <<EOF
57+
M a/alpha.txt
58+
EOF
59+
test_expect_success 'Create a patch' '
60+
echo "change" >> a/alpha.txt &&
61+
stg new --refresh -m patch0 &&
62+
cone_intact &&
63+
clean_status &&
64+
stg files >files-out &&
65+
test_cmp files-expected files-out
66+
'
67+
68+
test_expect_success 'Edit a patch' '
69+
stg edit --sign -d --save-template edit-out &&
70+
sed -e "s/^\+change/+CHANGE/g" edit-out > edited-out &&
71+
stg edit -f edited-out
72+
stg show >out &&
73+
grep "Signed-off-by:" out &&
74+
grep "CHANGE" out &&
75+
cone_intact &&
76+
clean_status &&
77+
stg files >files-out &&
78+
test_cmp files-expected files-out
79+
'
80+
81+
cat > files-expected <<EOF
82+
M a/alpha.txt
83+
M b/1/beta.txt
84+
EOF
85+
test_expect_success 'Refresh a patch' '
86+
echo "another change" >> a/alpha.txt &&
87+
echo "change" >> b/1/beta.txt &&
88+
stg refresh &&
89+
cone_intact &&
90+
clean_status &&
91+
stg files >files-out &&
92+
test_cmp files-expected files-out
93+
'
94+
95+
test_expect_success 'Pop a patch' '
96+
stg pop &&
97+
cone_intact &&
98+
clean_status
99+
'
100+
101+
test_expect_success 'Push a patch' '
102+
stg push &&
103+
cone_intact &&
104+
clean_status
105+
'
106+
107+
cat > files-expected <<EOF
108+
M b/1/beta.txt
109+
EOF
110+
test_expect_success 'Add a patch from subdir' '
111+
(
112+
cd b/1 &&
113+
echo "change from patch1" >> beta.txt &&
114+
stg new --refresh -m patch1
115+
) &&
116+
cone_intact &&
117+
clean_status &&
118+
stg files >files-out &&
119+
test_cmp files-expected files-out
120+
121+
'
122+
123+
cat > status-expected <<EOF
124+
UU b/1/beta.txt
125+
EOF
126+
test_expect_success 'Create merge conflict' '
127+
stg pop -a &&
128+
cone_intact &&
129+
clean_status &&
130+
conflict stg push patch1 &&
131+
stg status >status-out &&
132+
test_cmp status-expected status-out
133+
'
134+
135+
test_expect_success 'Resove conflict and refresh' '
136+
echo "change from patch0 and patch1" > b/1/beta.txt &&
137+
stg add b &&
138+
stg refresh &&
139+
cone_intact &&
140+
clean_status &&
141+
stg files >files-out &&
142+
test_cmp files-expected files-out
143+
'
144+
145+
cat > files-expected <<EOF
146+
A a/bar.txt
147+
EOF
148+
test_expect_success 'Add patch with new file inside cone' '
149+
echo "new content" > a/bar.txt &&
150+
stg add a/bar.txt &&
151+
stg new --refresh -m patch2 &&
152+
cone_intact &&
153+
clean_status &&
154+
stg files >files-out &&
155+
test_cmp files-expected files-out
156+
'
157+
158+
cat > files-expected <<EOF
159+
M a/alpha.txt
160+
M d/0/delta.txt
161+
A d/outside.txt
162+
EOF
163+
test_expect_success 'Add patch with files outside cone' '
164+
mkdir d &&
165+
echo "stuff" > d/outside.txt &&
166+
mkdir -p d/0 &&
167+
echo "addition" >> d/0/delta.txt &&
168+
general_error stg add d &&
169+
echo "more" >> a/alpha.txt &&
170+
stg add --sparse d a &&
171+
stg new -r -m patch3 &&
172+
cone_files_present &&
173+
test_path_is_file d/outside.txt &&
174+
clean_status &&
175+
stg files >files-out &&
176+
test_cmp files-expected files-out
177+
'
178+
179+
test_expect_success 'Pop and push patch with extra-conal files' '
180+
stg pop &&
181+
cone_intact &&
182+
clean_status &&
183+
stg push &&
184+
cone_intact &&
185+
clean_status &&
186+
test_path_is_missing d/outside.txt &&
187+
stg files >files-out &&
188+
test_cmp files-expected files-out
189+
'
190+
191+
test_expect_success 'Delete a patch' '
192+
stg delete --top &&
193+
cone_intact &&
194+
clean_status
195+
'
196+
197+
test_done

0 commit comments

Comments
 (0)