README_DOCS.rst: update tg prev and tg next usage summary
[topgit/pro.git] / t / t2100-create.sh
blobf6d2fa0f5f654b5ee8e29355778bf9deac924042
1 #!/bin/sh
3 test_description='tg create tests'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 test_plan 17
11 test_recreate_repo_cd() {
12 ! [ -e "$1" ] || rm -rf "$1"
13 ! [ -e "$1" ] || { chmod -R u+rw "$1"; rm -rf "$1"; }
14 ! [ -e "$1" ] || die
15 test_create_repo "$1" &&
16 cd "$1"
19 test_expect_success 'tg create works' '
20 test_recreate_repo_cd r0 &&
21 test_commit first &&
22 tg create --topmsg subject:tgbranch tgb &&
23 printf "%s\n" first >expected &&
24 test_diff expected first.t &&
25 printf "%s\n" subject:tgbranch >expected &&
26 test_diff expected .topmsg &&
27 printf "%s\n" master >expected &&
28 test_diff expected .topdeps &&
29 cnt="$(git rev-list --count HEAD)" &&
30 test $cnt -eq 2
33 test_expect_success 'tg create bad usage' '
34 test_recreate_repo_cd r0 &&
35 test_must_fail tg create &&
36 test_must_fail tg create --no-deps &&
37 test_must_fail tg create --base &&
38 test_must_fail tg create HEAD &&
39 test_must_fail tg create @ &&
40 test_must_fail tg create --no-deps foo bar &&
41 test_must_fail tg create --no-commit --no-update --no-deps HEAD &&
42 test_commit first^1 &&
43 git branch master2 &&
44 test_must_fail tg create master &&
45 test_must_fail tg create HEAD &&
46 test_must_fail tg create @ &&
47 test_must_fail tg create tgbranch xmaster &&
48 test_must_fail tg create tgbranch master xmaster &&
49 test_must_fail tg create tgbranch xmaster master &&
50 test_must_fail tg create --no-deps tgbranch xmaster master &&
51 test_must_fail tg create --no-deps tgbranch master xmaster
54 test_expect_success 'tg create reformats subject and works on unborn HEAD' '
55 test_recreate_repo_cd r0 &&
56 tg create --no-deps --topmsg first HEAD &&
57 test z"$(git symbolic-ref HEAD)" = z"refs/heads/master" &&
58 test -e .topdeps && test ! -s .topdeps &&
59 printf "%s\n" "Subject: [ROOT] first" >expected &&
60 test_diff expected .topmsg &&
61 cnt="$(git rev-list --count HEAD)" &&
62 test $cnt -eq 2 # still two with empty base commit
65 test_expect_success 'tg create reformats subject and works on unborn @' '
66 test_recreate_repo_cd r0 &&
67 tg create --no-deps --topmsg first @ &&
68 test z"$(git symbolic-ref HEAD)" = z"refs/heads/master" &&
69 test -e .topdeps && test ! -s .topdeps &&
70 printf "%s\n" "Subject: [ROOT] first" >expected &&
71 test_diff expected .topmsg &&
72 cnt="$(git rev-list --count HEAD)" &&
73 test $cnt -eq 2 # still two with empty base commit
76 test_expect_success 'tg create reformats subject and works on unborn master' '
77 test_recreate_repo_cd r0 &&
78 tg create --no-deps --topmsg first master &&
79 test z"$(git symbolic-ref HEAD)" = z"refs/heads/master" &&
80 test -e .topdeps && test ! -s .topdeps &&
81 printf "%s\n" "Subject: [ROOT] first" >expected &&
82 test_diff expected .topmsg &&
83 cnt="$(git rev-list --count HEAD)" &&
84 test $cnt -eq 2 # still two with empty base commit
87 test_expect_success 'tg create reformats subject and works on unborn anything' '
88 test_recreate_repo_cd r0 &&
89 tg create --no-deps --topmsg first anything &&
90 test z"$(git symbolic-ref HEAD)" = z"refs/heads/anything" &&
91 test -e .topdeps && test ! -s .topdeps &&
92 printf "%s\n" "Subject: [ROOT] first" >expected &&
93 test_diff expected .topmsg &&
94 cnt="$(git rev-list --count HEAD)" &&
95 test $cnt -eq 2 # still two with empty base commit
98 test_expect_success 'tg create --no-deps reformats subject as [BASE]' '
99 test_recreate_repo_cd r0 &&
100 test_commit first &&
101 tg create --no-deps --topmsg first tgb HEAD &&
102 test -e .topdeps && test ! -s .topdeps &&
103 printf "%s\n" "Subject: [BASE] first" >expected &&
104 test_diff expected .topmsg &&
105 cnt="$(git rev-list --count HEAD)" &&
106 test $cnt -eq 2
109 test_expect_success 'tg create --base reformats subject as [BASE]' '
110 test_recreate_repo_cd r0 &&
111 test_commit first &&
112 tg create --no-deps --topmsg first tgb HEAD &&
113 test -e .topdeps && test ! -s .topdeps &&
114 printf "%s\n" "Subject: [BASE] first" >expected &&
115 test_diff expected .topmsg &&
116 cnt="$(git rev-list --count HEAD)" &&
117 test $cnt -eq 2
120 test_expect_success 'tg create --base works with explicit branch' '
121 test_recreate_repo_cd r0 &&
122 test_commit first &&
123 tg create --no-deps --topmsg first tgb master &&
124 test -e .topdeps && test ! -s .topdeps &&
125 printf "%s\n" "Subject: [BASE] first" >expected &&
126 test_diff expected .topmsg &&
127 cnt="$(git rev-list --count HEAD)" &&
128 test $cnt -eq 2
131 test_expect_success 'tg create --base works with explicit non-HEAD branch' '
132 test_recreate_repo_cd r0 &&
133 test_commit first &&
134 git branch start &&
135 test_commit second &&
136 tg create --no-deps --topmsg first tgb start &&
137 test -e .topdeps && test ! -s .topdeps &&
138 printf "%s\n" "Subject: [BASE] first" >expected &&
139 test_diff expected .topmsg &&
140 cnt="$(git rev-list --count HEAD)" &&
141 test $cnt -eq 2
144 test_expect_success 'tg create --base works with explicit non-branch ref' '
145 test_recreate_repo_cd r0 &&
146 test_commit first && # creates tag "first"
147 git branch start &&
148 test_commit second &&
149 tg create --no-deps --topmsg first tgb first^0 &&
150 test -e .topdeps && test ! -s .topdeps &&
151 printf "%s\n" "Subject: [BASE] first" >expected &&
152 test_diff expected .topmsg &&
153 cnt="$(git rev-list --count HEAD)" &&
154 test $cnt -eq 2
157 test_expect_success 'tg create --base works with explicit non-branch ref' '
158 test_recreate_repo_cd r0 &&
159 test_commit first && # creates tag "first"
160 git branch start &&
161 test_commit second &&
162 tg create --no-deps --topmsg first tgb first^0 &&
163 test -e .topdeps && test ! -s .topdeps &&
164 printf "%s\n" "Subject: [BASE] first" >expected &&
165 test_diff expected .topmsg &&
166 cnt="$(git rev-list --count HEAD)" &&
167 test $cnt -eq 2
170 test_expect_success 'tg create with @' '
171 test_recreate_repo_cd r0 &&
172 test_commit first^one &&
173 git checkout master && # should be nop
174 tg create --topmsg subject:t/master t/master @ &&
175 cnt="$(git rev-list --count HEAD)" &&
176 test $cnt -eq 2
179 test_expect_success 'tg create multiple deps' '
180 test_recreate_repo_cd r0 &&
181 test_commit first^one &&
182 git branch first &&
183 test_commit second^one &&
184 tg create --topmsg subject:multi tgb first @ &&
185 printf "%s\n" first master >expected &&
186 test_diff expected .topdeps &&
187 printf "%s\n" "subject:multi" >expected &&
188 test_diff expected .topmsg &&
189 cnt="$(git rev-list --count HEAD)" &&
190 test $cnt -eq 4 &&
191 test_cmp_rev tgb HEAD &&
192 test_cmp_rev first HEAD^^ &&
193 test_cmp_rev master HEAD^2 &&
194 cnt="$(git rev-list --count HEAD^)" &&
195 test $cnt -eq 2 &&
196 pcnt="$(git --no-pager log --no-color --format=format:%p -n 1 tgb | wc -w)" &&
197 test $pcnt -eq 2
200 test_expect_success 'tg create --no-commit' '
201 test_recreate_repo_cd r0 &&
202 test_commit first^one &&
203 git checkout master && # should be nop
204 tg create --no-commit --topmsg subject:t/master t/master @ &&
205 printf "%s\n" master >expected &&
206 test_diff expected .topdeps &&
207 printf "%s\n" "subject:t/master" >expected &&
208 test_diff expected .topmsg &&
209 cnt="$(git rev-list --count --all)" &&
210 test $cnt -eq 1
213 test_expect_success 'tg create multiple deps --no-commit' '
214 test_recreate_repo_cd r0 &&
215 test_commit first^one &&
216 git branch first &&
217 test_commit second^one &&
218 tg create --no-commit --topmsg subject:multi tgb first @ &&
219 printf "%s\n" first master >expected &&
220 test_diff expected .topdeps &&
221 printf "%s\n" "subject:multi" >expected &&
222 test_diff expected .topmsg &&
223 cnt="$(git rev-list --count --all)" &&
224 test $cnt -eq 2 &&
225 test_cmp_rev first HEAD &&
226 test_cmp_rev first tgb &&
227 test_cmp_rev first $(tg base tgb)
230 test_expect_success 'tg create multiple deps --no-update' '
231 test_recreate_repo_cd r0 &&
232 test_commit first^one &&
233 git branch first &&
234 test_commit second^one &&
235 tg create --no-update --topmsg subject:multi tgb first @ &&
236 printf "%s\n" first master >expected &&
237 test_diff expected .topdeps &&
238 printf "%s\n" "subject:multi" >expected &&
239 test_diff expected .topmsg &&
240 cnt="$(git rev-list --count --all)" &&
241 test $cnt -eq 3 &&
242 test_cmp_rev tgb HEAD &&
243 test_cmp_rev first tgb^ &&
244 test_cmp_rev first $(tg base tgb) &&
245 pcnt="$(git --no-pager log --no-color --format=format:%p -n 1 tgb | wc -w)" &&
246 test $pcnt -eq 1
249 test_done