tg.sh: handle help -h
[topgit/pro.git] / t / t4500-contains.sh
blobefc19cfa1d13b59ab2a1ab768451b5d689f4bc89
1 #!/bin/sh
3 test_description='tg contains'
5 . ./test-lib.sh
7 test_plan 19
9 make_commits() {
10 test_commit "${1}initial" &&
11 test_commit "${1}a" && {
12 br="$(git symbolic-ref -q HEAD)" ||
13 br="$(git rev-parse --verify -q HEAD)"; } &&
14 git checkout --detach -f HEAD^ &&
15 test_commit "${1}b" &&
16 mc="$(git rev-parse --verify HEAD)" &&
17 git checkout -f "${br#refs/heads/}" &&
18 git merge -m "merge ${1}a and ${1}b" "$mc" &&
19 git tag "${1}m" &&
20 test_commit "${1}after"
23 new_branch() {
24 git checkout --detach empty &&
25 { git update-ref -d "refs/heads/$1" >/dev/null 2>&1 || :; } &&
26 git checkout --orphan "$1"
29 test_expect_success 'setup' '
30 git config core.logallrefupdates false &&
31 git config advice.detachedHead false &&
32 git config topgit.remote origin &&
33 git checkout --orphan empty &&
34 test_tick &&
35 git commit --allow-empty -m empty &&
36 mtc="$(git rev-parse --verify HEAD)" &&
37 git tag empty &&
38 git checkout --orphan build &&
39 git update-ref -d refs/heads/empty &&
40 # remote1
41 make_commits "remote1" &&
42 git update-ref refs/remotes/origin/remote1 HEAD &&
43 # remote2
44 new_branch build &&
45 make_commits "remote2" &&
46 git update-ref refs/remotes/origin/remote2 HEAD &&
47 # local1
48 new_branch build &&
49 make_commits "local1" &&
50 git branch -m local1 &&
51 # local2
52 new_branch build &&
53 make_commits "local2" &&
54 git branch -m local2 &&
55 # tgremote1
56 new_branch build &&
57 make_commits "tgremotepre1" &&
58 tg_test_create_branch origin:tgremote1 :HEAD &&
59 git update-ref HEAD refs/remotes/origin/tgremote1 &&
60 make_commits "tgremote1" &&
61 git update-ref refs/remotes/origin/tgremote1 HEAD &&
62 make_commits "tgremotepost1" &&
63 # tgremote2
64 make_commits "tgremotepre2" &&
65 tg_test_create_branch origin:tgremote2 :HEAD tgremote1 &&
66 git update-ref HEAD refs/remotes/origin/tgremote2 &&
67 make_commits "tgremote2" &&
68 git update-ref refs/remotes/origin/tgremote2 HEAD &&
69 make_commits "tgremotepost2" &&
70 # tglocal1
71 new_branch build &&
72 make_commits "tglocalpre1" &&
73 tg_test_create_branch tglocal1 :HEAD &&
74 git checkout -f tglocal1 &&
75 make_commits "tglocal1" &&
76 git checkout -f -B build &&
77 make_commits "tglocalpost1" &&
78 # tglocal2
79 make_commits "tglocalpre2" &&
80 tg_test_create_branch tglocal2 :HEAD tglocal1 &&
81 git checkout -f tglocal2 &&
82 make_commits "tglocal2" &&
83 git checkout -f -B build &&
84 make_commits "tglocalpost2" &&
85 # tgbranch1 local+remote
86 new_branch build &&
87 make_commits "tgbranchpre1" &&
88 tg_test_create_branch origin::tgbranch1 :HEAD &&
89 git checkout -f tgbranch1 &&
90 make_commits "tgbranch1" &&
91 git update-ref refs/remotes/origin/tgbranch1 HEAD &&
92 git checkout -f HEAD^0 &&
93 make_commits "tgbranchlpost1" &&
94 git checkout -f tgbranch1^0 &&
95 make_commits "tgbranchrpost1" &&
96 # tgbranch2 remote
97 make_commits "tgbranchrpre2" &&
98 tg_test_create_branch origin:tgbranch2 :HEAD tgbranch1 &&
99 git update-ref HEAD refs/remotes/origin/tgbranch2 &&
100 make_commits "tgbranchr2" &&
101 git update-ref refs/remotes/origin/tgbranch2 HEAD &&
102 make_commits "tgbranchrpost2" &&
103 # tgbranch2 local
104 git checkout -f tgbranchlpost1after &&
105 git merge -s ours -m "merge tgbranchrpost1" tgbranchrpost1after &&
106 make_commits "tgbranchlpre2" &&
107 tg_test_create_branch tgbranch2 :HEAD tgbranch1 &&
108 git checkout -f tgbranch2 &&
109 make_commits "tgbranchl2" &&
110 git checkout -f HEAD^0 &&
111 make_commits "tgbranchlpost2" &&
112 new_branch build &&
113 make_commits "tgcombinedpre" &&
114 tg_test_create_branch origin::tgcombined :HEAD tglocal1 tgbranch1 &&
115 git checkout -f HEAD^0 &&
116 make_commits "tgcombinedpost" &&
117 git checkout -B build &&
118 git repack -a -d &&
119 git pack-refs --prune --all &&
120 refcnt=$(git for-each-ref | wc -l) &&
121 test "$refcnt" = 166 &&
122 topbases="$(tg --top-bases)" &&
123 topbases="${topbases#refs/}" &&
124 test -n "$topbases" &&
125 test_when_finished topbases="$topbases" &&
126 test_when_finished test_set_prereq SETUP
129 test_expect_success SETUP 'no non-TopGit local branch matches' '
130 for r in local1a local1b local1m local2a local2b local2m; do
131 h="$(git rev-parse --verify -q $r)" &&
132 { tb="$(tg contains $r)" || :; } &&
133 test -z "$tb" &&
134 { tb="$(tg contains -r $r)" || :; } &&
135 test -z "$tb" &&
136 { tb="$(tg contains -r --ann $r)" || :; } &&
137 test -z "$tb" &&
138 { tb="$(tg contains --no-strict -r --ann $r)" || :; } &&
139 test -z "$tb" || return
140 done
143 test_expect_success SETUP 'no non-TopGit remote branch matches' '
144 for r in remote1a remote1b remote1m remote2a remote2b remote2m; do
145 h="$(git rev-parse --verify -q $r)" &&
146 { tb="$(tg contains $r)" || :; } &&
147 test -z "$tb" &&
148 { tb="$(tg contains -r $r)" || :; } &&
149 test -z "$tb" &&
150 { tb="$(tg contains -r --ann $r)" || :; } &&
151 test -z "$tb" &&
152 { tb="$(tg contains --no-strict -r --ann $r)" || :; } &&
153 test -z "$tb" || return
154 done
157 test_expect_success SETUP 'no --strict match for commits outside local tg branches' '
158 for r in tglocalpre1a tglocalpre1b tglocalpre1m tglocalpost1b tglocalpre2a tglocalpost2m; do
159 h="$(git rev-parse --verify -q $r)" &&
160 { tb="$(tg contains --strict $r)" || :; } &&
161 test -z "$tb" &&
162 { tb="$(tg contains --strict -r $r)" || :; } &&
163 test -z "$tb" &&
164 { tb="$(tg contains --strict -r --ann $r)" || :; } &&
165 test -z "$tb" &&
166 { tb="$(tg contains --strict --ann $r)" || :; } &&
167 test -z "$tb" || return
168 done
171 test_expect_success SETUP 'no --strict match for commits outside remote-only tg branches' '
172 for r in tgremotepre1a tgremotepre1b tgremotepre1m tgremotepost1b tgremotepre2a tgremotepost2m; do
173 h="$(git rev-parse --verify -q $r)" &&
174 { tb="$(tg contains --strict $r)" || :; } &&
175 test -z "$tb" &&
176 { tb="$(tg contains --strict -r $r)" || :; } &&
177 test -z "$tb" &&
178 { tb="$(tg contains --strict -r --ann $r)" || :; } &&
179 test -z "$tb" &&
180 { tb="$(tg contains --strict --ann $r)" || :; } &&
181 test -z "$tb" || return
182 done
185 test_expect_success SETUP 'no --strict match for commits outside local+remote tg branches' '
186 for r in tgbranchpre1a tgbranchpre1b tgbranchpre1m tgbranchlpost1b tgbranchrpost1b \
187 tgbranchrpre2m tgbranchrpost2m tgbranchlpre2m tgbranchlpost2a tgbranchlpost2b; do
188 h="$(git rev-parse --verify -q $r)" &&
189 { tb="$(tg contains --strict $r)" || :; } &&
190 test -z "$tb" &&
191 { tb="$(tg contains --strict -r $r)" || :; } &&
192 test -z "$tb" &&
193 { tb="$(tg contains --strict -r --ann $r)" || :; } &&
194 test -z "$tb" &&
195 { tb="$(tg contains --strict --ann $r)" || :; } &&
196 test -z "$tb" || return
197 done
200 test_expect_success SETUP 'contains matches tglocal1' '
201 for r in tglocal1a tglocal1b tglocal1m; do
202 h="$(git rev-parse --verify -q $r)" &&
203 tb="$(tg contains --strict $r)" &&
204 test "$tb" = "tglocal1" &&
205 tb="$(tg contains --no-strict -r --ann $r)" &&
206 test "$tb" = "tglocal1" || return
207 done
210 test_expect_success SETUP 'contains matches tglocal2' '
211 for r in tglocal2a tglocal2b tglocal2m; do
212 h="$(git rev-parse --verify -q $r)" &&
213 tb="$(tg contains --strict $r)" &&
214 test "$tb" = "tglocal2" &&
215 tb="$(tg contains --no-strict -r --ann $r)" &&
216 test "$tb" = "tglocal2" || return
217 done
220 test_expect_success SETUP 'contains matches tgremote1 only with -r' '
221 for r in tgremote1a tgremote1b tgremote1m; do
222 h="$(git rev-parse --verify -q $r)" &&
223 { tb="$(tg contains --strict $r)" || :; } &&
224 test -z "$tb" &&
225 tb="$(tg contains -r $r)" &&
226 test "$tb" = "remotes/origin/tgremote1" &&
227 tb="$(tg contains --no-strict -r --ann $r)" &&
228 test "$tb" = "remotes/origin/tgremote1" || return
229 done
232 test_expect_success SETUP 'contains matches tgremote2 only with -r' '
233 for r in tgremote2a tgremote2b tgremote2m; do
234 h="$(git rev-parse --verify -q $r)" &&
235 { tb="$(tg contains --strict $r)" || :; } &&
236 test -z "$tb" &&
237 tb="$(tg contains -r $r)" &&
238 test "$tb" = "remotes/origin/tgremote2" &&
239 tb="$(tg contains --no-strict -r --ann $r)" &&
240 test "$tb" = "remotes/origin/tgremote2" || return
241 done
244 test_expect_success SETUP 'contains never remote match if local match' '
245 for r in tgbranch1a tgbranch1b tgbranch1m; do
246 h="$(git rev-parse --verify -q $r)" &&
247 tb="$(tg contains $r)" &&
248 test "$tb" = "tgbranch1" &&
249 tb="$(tg contains --no-strict -r --ann $r)" &&
250 test "$tb" = "tgbranch1" || return
251 done
254 test_expect_success SETUP 'contains local bases only with --no-strict' '
255 for r in tglocal1 tglocal2 tgbranch1 tgbranch2; do
256 h="$(git rev-parse --verify -q "refs/$topbases/$r")" &&
257 { tb="$(tg contains --strict -r --ann $h)" || :; } &&
258 test -z "$tb" &&
259 tb="$(tg contains --no-strict $h)" &&
260 test "$tb" = "$r" || return
261 done
264 test_expect_success SETUP 'contains remote bases only with --no-strict -r' '
265 for r in tgremote1 tgremote2; do
266 h="$(git rev-parse --verify -q "refs/remotes/origin/${topbases#heads/}/$r")" &&
267 { tb="$(tg contains --strict -r --ann $h)" || :; } &&
268 test -z "$tb" &&
269 { tb="$(tg contains --no-strict --ann $h)" || :; } &&
270 test -z "$tb" &&
271 tb="$(tg contains --no-strict -r $h)" &&
272 test "$tb" = "remotes/origin/$r" || return
273 done
276 test_expect_success SETUP 'contains -v local one head' '
277 tb="$(tg contains -v tglocal2b)" &&
278 test "$tb" = "tglocal2 [tglocal2]"
281 test_expect_success SETUP 'contains -v local+remote one head' '
282 tb="$(tg contains -v tgbranchl2b)" &&
283 test "$tb" = "tgbranch2 [tgbranch2]"
286 test_expect_success SETUP 'contains -v remote no heads' '
287 { tb="$(tg contains -v --no-strict --ann tgremote2b)" || :; } &&
288 test -z "$tb" &&
289 tb="$(tg contains -v -r tgremote2b)" &&
290 test "$tb" = "remotes/origin/tgremote2"
293 test_expect_success SETUP 'contains -v local+remote out-of-date no heads' '
294 { tb="$(tg contains -v --no-strict --ann tgbranchr2b)" || :; } &&
295 test -z "$tb" &&
296 tb="$(tg contains -v -r tgbranchr2b)" &&
297 test "$tb" = "remotes/origin/tgbranch2"
300 test_expect_success SETUP 'contains -v two heads local' '
301 tb="$(tg contains -v tglocal1b)" &&
302 test "$tb" = "tglocal1 [tgcombined, tglocal2]"
305 test_expect_success SETUP 'contains -v two heads local+remote' '
306 tb="$(tg contains -v tgbranch1b)" &&
307 test "$tb" = "tgbranch1 [tgbranch2, tgcombined]"
310 test_done