]>
Commit | Line | Data |
---|---|---|
963c0407 SG |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2012 SZEDER Gábor | |
4 | # | |
5 | ||
6 | test_description='test git-specific bash prompt functions' | |
7 | ||
8 | . ./lib-bash.sh | |
9 | ||
af31a456 | 10 | . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh" |
963c0407 SG |
11 | |
12 | actual="$TRASH_DIRECTORY/actual" | |
13 | ||
14 | test_expect_success 'setup for prompt tests' ' | |
963c0407 | 15 | git init otherrepo && |
4fe00b4f | 16 | echo 1 >file && |
963c0407 SG |
17 | git add file && |
18 | test_tick && | |
19 | git commit -m initial && | |
20 | git tag -a -m msg1 t1 && | |
21 | git checkout -b b1 && | |
4fe00b4f | 22 | echo 2 >file && |
963c0407 | 23 | git commit -m "second b1" file && |
4fe00b4f | 24 | echo 3 >file && |
963c0407 SG |
25 | git commit -m "third b1" file && |
26 | git tag -a -m msg2 t2 && | |
27 | git checkout -b b2 master && | |
4fe00b4f | 28 | echo 0 >file && |
963c0407 | 29 | git commit -m "second b2" file && |
4fe00b4f | 30 | echo 00 >file && |
b71dc3e1 | 31 | git commit -m "another b2" file && |
4fe00b4f | 32 | echo 000 >file && |
b71dc3e1 | 33 | git commit -m "yet another b2" file && |
963c0407 SG |
34 | git checkout master |
35 | ' | |
36 | ||
963c0407 | 37 | test_expect_success 'prompt - branch name' ' |
4fe00b4f SG |
38 | printf " (master)" >expected && |
39 | __git_ps1 >"$actual" && | |
963c0407 SG |
40 | test_cmp expected "$actual" |
41 | ' | |
42 | ||
868dc1ac SG |
43 | test_expect_success SYMLINKS 'prompt - branch name - symlink symref' ' |
44 | printf " (master)" >expected && | |
45 | test_when_finished "git checkout master" && | |
46 | test_config core.preferSymlinkRefs true && | |
47 | git checkout master && | |
48 | __git_ps1 >"$actual" && | |
49 | test_cmp expected "$actual" | |
50 | ' | |
51 | ||
963c0407 | 52 | test_expect_success 'prompt - detached head' ' |
e8f21caf SG |
53 | printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected && |
54 | test_config core.abbrev 13 && | |
963c0407 SG |
55 | git checkout b1^ && |
56 | test_when_finished "git checkout master" && | |
4fe00b4f | 57 | __git_ps1 >"$actual" && |
963c0407 SG |
58 | test_cmp expected "$actual" |
59 | ' | |
60 | ||
61 | test_expect_success 'prompt - describe detached head - contains' ' | |
4fe00b4f | 62 | printf " ((t2~1))" >expected && |
963c0407 SG |
63 | git checkout b1^ && |
64 | test_when_finished "git checkout master" && | |
65 | ( | |
66 | GIT_PS1_DESCRIBE_STYLE=contains && | |
4fe00b4f | 67 | __git_ps1 >"$actual" |
963c0407 SG |
68 | ) && |
69 | test_cmp expected "$actual" | |
70 | ' | |
71 | ||
72 | test_expect_success 'prompt - describe detached head - branch' ' | |
4fe00b4f | 73 | printf " ((b1~1))" >expected && |
963c0407 SG |
74 | git checkout b1^ && |
75 | test_when_finished "git checkout master" && | |
76 | ( | |
77 | GIT_PS1_DESCRIBE_STYLE=branch && | |
4fe00b4f | 78 | __git_ps1 >"$actual" |
963c0407 SG |
79 | ) && |
80 | test_cmp expected "$actual" | |
81 | ' | |
82 | ||
83 | test_expect_success 'prompt - describe detached head - describe' ' | |
4fe00b4f | 84 | printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) >expected && |
963c0407 SG |
85 | git checkout b1^ && |
86 | test_when_finished "git checkout master" && | |
87 | ( | |
88 | GIT_PS1_DESCRIBE_STYLE=describe && | |
4fe00b4f | 89 | __git_ps1 >"$actual" |
963c0407 SG |
90 | ) && |
91 | test_cmp expected "$actual" | |
92 | ' | |
93 | ||
94 | test_expect_success 'prompt - describe detached head - default' ' | |
4fe00b4f | 95 | printf " ((t2))" >expected && |
963c0407 SG |
96 | git checkout --detach b1 && |
97 | test_when_finished "git checkout master" && | |
4fe00b4f | 98 | __git_ps1 >"$actual" && |
963c0407 SG |
99 | test_cmp expected "$actual" |
100 | ' | |
101 | ||
102 | test_expect_success 'prompt - inside .git directory' ' | |
4fe00b4f | 103 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
104 | ( |
105 | cd .git && | |
4fe00b4f | 106 | __git_ps1 >"$actual" |
963c0407 SG |
107 | ) && |
108 | test_cmp expected "$actual" | |
109 | ' | |
110 | ||
111 | test_expect_success 'prompt - deep inside .git directory' ' | |
4fe00b4f | 112 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
113 | ( |
114 | cd .git/refs/heads && | |
4fe00b4f | 115 | __git_ps1 >"$actual" |
963c0407 SG |
116 | ) && |
117 | test_cmp expected "$actual" | |
118 | ' | |
119 | ||
120 | test_expect_success 'prompt - inside bare repository' ' | |
4fe00b4f | 121 | printf " (BARE:master)" >expected && |
963c0407 SG |
122 | git init --bare bare.git && |
123 | test_when_finished "rm -rf bare.git" && | |
124 | ( | |
125 | cd bare.git && | |
4fe00b4f | 126 | __git_ps1 >"$actual" |
963c0407 SG |
127 | ) && |
128 | test_cmp expected "$actual" | |
129 | ' | |
130 | ||
131 | test_expect_success 'prompt - interactive rebase' ' | |
4fe00b4f | 132 | printf " (b1|REBASE-i 2/3)" >expected |
7412290c SG |
133 | write_script fake_editor.sh <<-\EOF && |
134 | echo "exec echo" >"$1" | |
135 | echo "edit $(git log -1 --format="%h")" >>"$1" | |
136 | echo "exec echo" >>"$1" | |
137 | EOF | |
963c0407 | 138 | test_when_finished "rm -f fake_editor.sh" && |
963c0407 SG |
139 | test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" && |
140 | git checkout b1 && | |
141 | test_when_finished "git checkout master" && | |
142 | git rebase -i HEAD^ && | |
143 | test_when_finished "git rebase --abort" | |
4fe00b4f | 144 | __git_ps1 >"$actual" && |
963c0407 SG |
145 | test_cmp expected "$actual" |
146 | ' | |
147 | ||
148 | test_expect_success 'prompt - rebase merge' ' | |
4fe00b4f | 149 | printf " (b2|REBASE-m 1/3)" >expected && |
963c0407 SG |
150 | git checkout b2 && |
151 | test_when_finished "git checkout master" && | |
152 | test_must_fail git rebase --merge b1 b2 && | |
153 | test_when_finished "git rebase --abort" && | |
4fe00b4f | 154 | __git_ps1 >"$actual" && |
963c0407 SG |
155 | test_cmp expected "$actual" |
156 | ' | |
157 | ||
158 | test_expect_success 'prompt - rebase' ' | |
4fe00b4f | 159 | printf " (b2|REBASE 1/3)" >expected && |
963c0407 SG |
160 | git checkout b2 && |
161 | test_when_finished "git checkout master" && | |
162 | test_must_fail git rebase b1 b2 && | |
163 | test_when_finished "git rebase --abort" && | |
4fe00b4f | 164 | __git_ps1 >"$actual" && |
963c0407 SG |
165 | test_cmp expected "$actual" |
166 | ' | |
167 | ||
168 | test_expect_success 'prompt - merge' ' | |
4fe00b4f | 169 | printf " (b1|MERGING)" >expected && |
963c0407 SG |
170 | git checkout b1 && |
171 | test_when_finished "git checkout master" && | |
172 | test_must_fail git merge b2 && | |
173 | test_when_finished "git reset --hard" && | |
4fe00b4f | 174 | __git_ps1 >"$actual" && |
963c0407 SG |
175 | test_cmp expected "$actual" |
176 | ' | |
177 | ||
178 | test_expect_success 'prompt - cherry-pick' ' | |
4fe00b4f | 179 | printf " (master|CHERRY-PICKING)" >expected && |
963c0407 SG |
180 | test_must_fail git cherry-pick b1 && |
181 | test_when_finished "git reset --hard" && | |
4fe00b4f | 182 | __git_ps1 >"$actual" && |
963c0407 SG |
183 | test_cmp expected "$actual" |
184 | ' | |
185 | ||
186 | test_expect_success 'prompt - bisect' ' | |
4fe00b4f | 187 | printf " (master|BISECTING)" >expected && |
963c0407 SG |
188 | git bisect start && |
189 | test_when_finished "git bisect reset" && | |
4fe00b4f | 190 | __git_ps1 >"$actual" && |
963c0407 SG |
191 | test_cmp expected "$actual" |
192 | ' | |
193 | ||
194 | test_expect_success 'prompt - dirty status indicator - clean' ' | |
4fe00b4f | 195 | printf " (master)" >expected && |
963c0407 SG |
196 | ( |
197 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 198 | __git_ps1 >"$actual" |
963c0407 SG |
199 | ) && |
200 | test_cmp expected "$actual" | |
201 | ' | |
202 | ||
203 | test_expect_success 'prompt - dirty status indicator - dirty worktree' ' | |
4fe00b4f SG |
204 | printf " (master *)" >expected && |
205 | echo "dirty" >file && | |
963c0407 SG |
206 | test_when_finished "git reset --hard" && |
207 | ( | |
208 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 209 | __git_ps1 >"$actual" |
963c0407 SG |
210 | ) && |
211 | test_cmp expected "$actual" | |
212 | ' | |
213 | ||
214 | test_expect_success 'prompt - dirty status indicator - dirty index' ' | |
4fe00b4f SG |
215 | printf " (master +)" >expected && |
216 | echo "dirty" >file && | |
963c0407 SG |
217 | test_when_finished "git reset --hard" && |
218 | git add -u && | |
219 | ( | |
220 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 221 | __git_ps1 >"$actual" |
963c0407 SG |
222 | ) && |
223 | test_cmp expected "$actual" | |
224 | ' | |
225 | ||
226 | test_expect_success 'prompt - dirty status indicator - dirty index and worktree' ' | |
4fe00b4f SG |
227 | printf " (master *+)" >expected && |
228 | echo "dirty index" >file && | |
963c0407 SG |
229 | test_when_finished "git reset --hard" && |
230 | git add -u && | |
4fe00b4f | 231 | echo "dirty worktree" >file && |
963c0407 SG |
232 | ( |
233 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 234 | __git_ps1 >"$actual" |
963c0407 SG |
235 | ) && |
236 | test_cmp expected "$actual" | |
237 | ' | |
238 | ||
239 | test_expect_success 'prompt - dirty status indicator - before root commit' ' | |
4fe00b4f | 240 | printf " (master #)" >expected && |
963c0407 SG |
241 | ( |
242 | GIT_PS1_SHOWDIRTYSTATE=y && | |
243 | cd otherrepo && | |
4fe00b4f | 244 | __git_ps1 >"$actual" |
963c0407 SG |
245 | ) && |
246 | test_cmp expected "$actual" | |
247 | ' | |
248 | ||
dc7e7bce | 249 | test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' ' |
4fe00b4f SG |
250 | printf " (master)" >expected && |
251 | echo "dirty" >file && | |
963c0407 SG |
252 | test_when_finished "git reset --hard" && |
253 | test_config bash.showDirtyState false && | |
dc7e7bce MEW |
254 | ( |
255 | sane_unset GIT_PS1_SHOWDIRTYSTATE && | |
4fe00b4f | 256 | __git_ps1 >"$actual" |
dc7e7bce MEW |
257 | ) && |
258 | test_cmp expected "$actual" | |
259 | ' | |
260 | ||
261 | test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' ' | |
4fe00b4f SG |
262 | printf " (master)" >expected && |
263 | echo "dirty" >file && | |
dc7e7bce MEW |
264 | test_when_finished "git reset --hard" && |
265 | test_config bash.showDirtyState true && | |
266 | ( | |
267 | sane_unset GIT_PS1_SHOWDIRTYSTATE && | |
4fe00b4f | 268 | __git_ps1 >"$actual" |
dc7e7bce MEW |
269 | ) && |
270 | test_cmp expected "$actual" | |
271 | ' | |
272 | ||
273 | test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' ' | |
4fe00b4f SG |
274 | printf " (master)" >expected && |
275 | echo "dirty" >file && | |
dc7e7bce MEW |
276 | test_when_finished "git reset --hard" && |
277 | test_config bash.showDirtyState false && | |
278 | ( | |
279 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 280 | __git_ps1 >"$actual" |
dc7e7bce MEW |
281 | ) && |
282 | test_cmp expected "$actual" | |
283 | ' | |
284 | ||
285 | test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' ' | |
4fe00b4f SG |
286 | printf " (master *)" >expected && |
287 | echo "dirty" >file && | |
dc7e7bce MEW |
288 | test_when_finished "git reset --hard" && |
289 | test_config bash.showDirtyState true && | |
963c0407 SG |
290 | ( |
291 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 292 | __git_ps1 >"$actual" |
963c0407 SG |
293 | ) && |
294 | test_cmp expected "$actual" | |
295 | ' | |
296 | ||
297 | test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' ' | |
4fe00b4f SG |
298 | printf " (GIT_DIR!)" >expected && |
299 | echo "dirty" >file && | |
963c0407 SG |
300 | test_when_finished "git reset --hard" && |
301 | ( | |
302 | GIT_PS1_SHOWDIRTYSTATE=y && | |
303 | cd .git && | |
4fe00b4f | 304 | __git_ps1 >"$actual" |
963c0407 SG |
305 | ) && |
306 | test_cmp expected "$actual" | |
307 | ' | |
308 | ||
309 | test_expect_success 'prompt - stash status indicator - no stash' ' | |
4fe00b4f | 310 | printf " (master)" >expected && |
963c0407 SG |
311 | ( |
312 | GIT_PS1_SHOWSTASHSTATE=y && | |
4fe00b4f | 313 | __git_ps1 >"$actual" |
963c0407 SG |
314 | ) && |
315 | test_cmp expected "$actual" | |
316 | ' | |
317 | ||
318 | test_expect_success 'prompt - stash status indicator - stash' ' | |
4fe00b4f | 319 | printf " (master $)" >expected && |
963c0407 SG |
320 | echo 2 >file && |
321 | git stash && | |
322 | test_when_finished "git stash drop" && | |
323 | ( | |
324 | GIT_PS1_SHOWSTASHSTATE=y && | |
4fe00b4f | 325 | __git_ps1 >"$actual" |
963c0407 SG |
326 | ) && |
327 | test_cmp expected "$actual" | |
328 | ' | |
329 | ||
330 | test_expect_success 'prompt - stash status indicator - not shown inside .git directory' ' | |
4fe00b4f | 331 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
332 | echo 2 >file && |
333 | git stash && | |
334 | test_when_finished "git stash drop" && | |
335 | ( | |
336 | GIT_PS1_SHOWSTASHSTATE=y && | |
337 | cd .git && | |
4fe00b4f | 338 | __git_ps1 >"$actual" |
963c0407 SG |
339 | ) && |
340 | test_cmp expected "$actual" | |
341 | ' | |
342 | ||
343 | test_expect_success 'prompt - untracked files status indicator - no untracked files' ' | |
4fe00b4f | 344 | printf " (master)" >expected && |
963c0407 SG |
345 | ( |
346 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
347 | cd otherrepo && | |
4fe00b4f | 348 | __git_ps1 >"$actual" |
963c0407 SG |
349 | ) && |
350 | test_cmp expected "$actual" | |
351 | ' | |
352 | ||
353 | test_expect_success 'prompt - untracked files status indicator - untracked files' ' | |
4fe00b4f | 354 | printf " (master %%)" >expected && |
963c0407 SG |
355 | ( |
356 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 357 | __git_ps1 >"$actual" |
963c0407 SG |
358 | ) && |
359 | test_cmp expected "$actual" | |
360 | ' | |
361 | ||
58978e82 | 362 | test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' ' |
4fe00b4f | 363 | printf " (master)" >expected && |
58978e82 MEW |
364 | test_config bash.showUntrackedFiles false && |
365 | ( | |
366 | sane_unset GIT_PS1_SHOWUNTRACKEDFILES && | |
4fe00b4f | 367 | __git_ps1 >"$actual" |
58978e82 MEW |
368 | ) && |
369 | test_cmp expected "$actual" | |
370 | ' | |
371 | ||
372 | test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' ' | |
4fe00b4f | 373 | printf " (master)" >expected && |
58978e82 MEW |
374 | test_config bash.showUntrackedFiles true && |
375 | ( | |
376 | sane_unset GIT_PS1_SHOWUNTRACKEDFILES && | |
4fe00b4f | 377 | __git_ps1 >"$actual" |
58978e82 MEW |
378 | ) && |
379 | test_cmp expected "$actual" | |
380 | ' | |
381 | ||
382 | test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' ' | |
4fe00b4f | 383 | printf " (master)" >expected && |
58978e82 MEW |
384 | test_config bash.showUntrackedFiles false && |
385 | ( | |
386 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 387 | __git_ps1 >"$actual" |
58978e82 MEW |
388 | ) && |
389 | test_cmp expected "$actual" | |
390 | ' | |
391 | ||
392 | test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' ' | |
4fe00b4f | 393 | printf " (master %%)" >expected && |
58978e82 MEW |
394 | test_config bash.showUntrackedFiles true && |
395 | ( | |
396 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 397 | __git_ps1 >"$actual" |
58978e82 MEW |
398 | ) && |
399 | test_cmp expected "$actual" | |
400 | ' | |
401 | ||
963c0407 | 402 | test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' ' |
4fe00b4f | 403 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
404 | ( |
405 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
406 | cd .git && | |
4fe00b4f | 407 | __git_ps1 >"$actual" |
963c0407 SG |
408 | ) && |
409 | test_cmp expected "$actual" | |
410 | ' | |
411 | ||
412 | test_expect_success 'prompt - format string starting with dash' ' | |
4fe00b4f SG |
413 | printf -- "-master" >expected && |
414 | __git_ps1 "-%s" >"$actual" && | |
963c0407 SG |
415 | test_cmp expected "$actual" |
416 | ' | |
417 | ||
418 | test_done |