]>
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" | |
1572e18e EA |
13 | c_red='\\[\\e[31m\\]' |
14 | c_green='\\[\\e[32m\\]' | |
15 | c_lblue='\\[\\e[1;34m\\]' | |
16 | c_clear='\\[\\e[0m\\]' | |
963c0407 SG |
17 | |
18 | test_expect_success 'setup for prompt tests' ' | |
963c0407 | 19 | git init otherrepo && |
4fe00b4f | 20 | echo 1 >file && |
963c0407 SG |
21 | git add file && |
22 | test_tick && | |
23 | git commit -m initial && | |
24 | git tag -a -m msg1 t1 && | |
25 | git checkout -b b1 && | |
4fe00b4f | 26 | echo 2 >file && |
963c0407 | 27 | git commit -m "second b1" file && |
4fe00b4f | 28 | echo 3 >file && |
963c0407 SG |
29 | git commit -m "third b1" file && |
30 | git tag -a -m msg2 t2 && | |
31 | git checkout -b b2 master && | |
4fe00b4f | 32 | echo 0 >file && |
963c0407 | 33 | git commit -m "second b2" file && |
4fe00b4f | 34 | echo 00 >file && |
b71dc3e1 | 35 | git commit -m "another b2" file && |
4fe00b4f | 36 | echo 000 >file && |
b71dc3e1 | 37 | git commit -m "yet another b2" file && |
0120b8c8 JA |
38 | mkdir ignored_dir && |
39 | echo "ignored_dir/" >>.gitignore && | |
963c0407 SG |
40 | git checkout master |
41 | ' | |
42 | ||
963c0407 | 43 | test_expect_success 'prompt - branch name' ' |
4fe00b4f SG |
44 | printf " (master)" >expected && |
45 | __git_ps1 >"$actual" && | |
963c0407 SG |
46 | test_cmp expected "$actual" |
47 | ' | |
48 | ||
868dc1ac SG |
49 | test_expect_success SYMLINKS 'prompt - branch name - symlink symref' ' |
50 | printf " (master)" >expected && | |
51 | test_when_finished "git checkout master" && | |
52 | test_config core.preferSymlinkRefs true && | |
53 | git checkout master && | |
54 | __git_ps1 >"$actual" && | |
55 | test_cmp expected "$actual" | |
56 | ' | |
57 | ||
e3e0b937 SG |
58 | test_expect_success 'prompt - unborn branch' ' |
59 | printf " (unborn)" >expected && | |
60 | git checkout --orphan unborn && | |
61 | test_when_finished "git checkout master" && | |
62 | __git_ps1 >"$actual" && | |
63 | test_cmp expected "$actual" | |
64 | ' | |
65 | ||
6ec63305 | 66 | if test_have_prereq !FUNNYNAMES; then |
a4889e64 SG |
67 | say 'Your filesystem does not allow newlines in filenames.' |
68 | fi | |
69 | ||
70 | test_expect_success FUNNYNAMES 'prompt - with newline in path' ' | |
6ec63305 WC |
71 | repo_with_newline="repo |
72 | with | |
73 | newline" && | |
74 | mkdir "$repo_with_newline" && | |
a4889e64 SG |
75 | printf " (master)" >expected && |
76 | git init "$repo_with_newline" && | |
77 | test_when_finished "rm -rf \"$repo_with_newline\"" && | |
78 | mkdir "$repo_with_newline"/subdir && | |
79 | ( | |
80 | cd "$repo_with_newline/subdir" && | |
81 | __git_ps1 >"$actual" | |
82 | ) && | |
83 | test_cmp expected "$actual" | |
84 | ' | |
85 | ||
963c0407 | 86 | test_expect_success 'prompt - detached head' ' |
e8f21caf SG |
87 | printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected && |
88 | test_config core.abbrev 13 && | |
963c0407 SG |
89 | git checkout b1^ && |
90 | test_when_finished "git checkout master" && | |
4fe00b4f | 91 | __git_ps1 >"$actual" && |
963c0407 SG |
92 | test_cmp expected "$actual" |
93 | ' | |
94 | ||
95 | test_expect_success 'prompt - describe detached head - contains' ' | |
4fe00b4f | 96 | printf " ((t2~1))" >expected && |
963c0407 SG |
97 | git checkout b1^ && |
98 | test_when_finished "git checkout master" && | |
99 | ( | |
100 | GIT_PS1_DESCRIBE_STYLE=contains && | |
4fe00b4f | 101 | __git_ps1 >"$actual" |
963c0407 SG |
102 | ) && |
103 | test_cmp expected "$actual" | |
104 | ' | |
105 | ||
106 | test_expect_success 'prompt - describe detached head - branch' ' | |
75504248 | 107 | printf " ((tags/t2~1))" >expected && |
963c0407 SG |
108 | git checkout b1^ && |
109 | test_when_finished "git checkout master" && | |
110 | ( | |
111 | GIT_PS1_DESCRIBE_STYLE=branch && | |
4fe00b4f | 112 | __git_ps1 >"$actual" |
963c0407 SG |
113 | ) && |
114 | test_cmp expected "$actual" | |
115 | ' | |
116 | ||
117 | test_expect_success 'prompt - describe detached head - describe' ' | |
4fe00b4f | 118 | printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) >expected && |
963c0407 SG |
119 | git checkout b1^ && |
120 | test_when_finished "git checkout master" && | |
121 | ( | |
122 | GIT_PS1_DESCRIBE_STYLE=describe && | |
4fe00b4f | 123 | __git_ps1 >"$actual" |
963c0407 SG |
124 | ) && |
125 | test_cmp expected "$actual" | |
126 | ' | |
127 | ||
128 | test_expect_success 'prompt - describe detached head - default' ' | |
4fe00b4f | 129 | printf " ((t2))" >expected && |
963c0407 SG |
130 | git checkout --detach b1 && |
131 | test_when_finished "git checkout master" && | |
4fe00b4f | 132 | __git_ps1 >"$actual" && |
963c0407 SG |
133 | test_cmp expected "$actual" |
134 | ' | |
135 | ||
136 | test_expect_success 'prompt - inside .git directory' ' | |
4fe00b4f | 137 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
138 | ( |
139 | cd .git && | |
4fe00b4f | 140 | __git_ps1 >"$actual" |
963c0407 SG |
141 | ) && |
142 | test_cmp expected "$actual" | |
143 | ' | |
144 | ||
145 | test_expect_success 'prompt - deep inside .git directory' ' | |
4fe00b4f | 146 | printf " (GIT_DIR!)" >expected && |
963c0407 | 147 | ( |
5340d471 | 148 | cd .git/objects && |
4fe00b4f | 149 | __git_ps1 >"$actual" |
963c0407 SG |
150 | ) && |
151 | test_cmp expected "$actual" | |
152 | ' | |
153 | ||
154 | test_expect_success 'prompt - inside bare repository' ' | |
4fe00b4f | 155 | printf " (BARE:master)" >expected && |
963c0407 SG |
156 | git init --bare bare.git && |
157 | test_when_finished "rm -rf bare.git" && | |
158 | ( | |
159 | cd bare.git && | |
4fe00b4f | 160 | __git_ps1 >"$actual" |
963c0407 SG |
161 | ) && |
162 | test_cmp expected "$actual" | |
163 | ' | |
164 | ||
165 | test_expect_success 'prompt - interactive rebase' ' | |
99094a7a | 166 | printf " (b1|REBASE-i 2/3)" >expected && |
7412290c SG |
167 | write_script fake_editor.sh <<-\EOF && |
168 | echo "exec echo" >"$1" | |
169 | echo "edit $(git log -1 --format="%h")" >>"$1" | |
170 | echo "exec echo" >>"$1" | |
171 | EOF | |
963c0407 | 172 | test_when_finished "rm -f fake_editor.sh" && |
963c0407 SG |
173 | test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" && |
174 | git checkout b1 && | |
175 | test_when_finished "git checkout master" && | |
176 | git rebase -i HEAD^ && | |
c00bfc9d | 177 | test_when_finished "git rebase --abort" && |
4fe00b4f | 178 | __git_ps1 >"$actual" && |
963c0407 SG |
179 | test_cmp expected "$actual" |
180 | ' | |
181 | ||
182 | test_expect_success 'prompt - rebase merge' ' | |
4fe00b4f | 183 | printf " (b2|REBASE-m 1/3)" >expected && |
963c0407 SG |
184 | git checkout b2 && |
185 | test_when_finished "git checkout master" && | |
186 | test_must_fail git rebase --merge b1 b2 && | |
187 | test_when_finished "git rebase --abort" && | |
4fe00b4f | 188 | __git_ps1 >"$actual" && |
963c0407 SG |
189 | test_cmp expected "$actual" |
190 | ' | |
191 | ||
192 | test_expect_success 'prompt - rebase' ' | |
4fe00b4f | 193 | printf " (b2|REBASE 1/3)" >expected && |
963c0407 SG |
194 | git checkout b2 && |
195 | test_when_finished "git checkout master" && | |
196 | test_must_fail git rebase b1 b2 && | |
197 | test_when_finished "git rebase --abort" && | |
4fe00b4f | 198 | __git_ps1 >"$actual" && |
963c0407 SG |
199 | test_cmp expected "$actual" |
200 | ' | |
201 | ||
202 | test_expect_success 'prompt - merge' ' | |
4fe00b4f | 203 | printf " (b1|MERGING)" >expected && |
963c0407 SG |
204 | git checkout b1 && |
205 | test_when_finished "git checkout master" && | |
206 | test_must_fail git merge b2 && | |
207 | test_when_finished "git reset --hard" && | |
4fe00b4f | 208 | __git_ps1 >"$actual" && |
963c0407 SG |
209 | test_cmp expected "$actual" |
210 | ' | |
211 | ||
212 | test_expect_success 'prompt - cherry-pick' ' | |
4fe00b4f | 213 | printf " (master|CHERRY-PICKING)" >expected && |
963c0407 SG |
214 | test_must_fail git cherry-pick b1 && |
215 | test_when_finished "git reset --hard" && | |
4fe00b4f | 216 | __git_ps1 >"$actual" && |
963c0407 SG |
217 | test_cmp expected "$actual" |
218 | ' | |
219 | ||
220 | test_expect_success 'prompt - bisect' ' | |
4fe00b4f | 221 | printf " (master|BISECTING)" >expected && |
963c0407 SG |
222 | git bisect start && |
223 | test_when_finished "git bisect reset" && | |
4fe00b4f | 224 | __git_ps1 >"$actual" && |
963c0407 SG |
225 | test_cmp expected "$actual" |
226 | ' | |
227 | ||
228 | test_expect_success 'prompt - dirty status indicator - clean' ' | |
4fe00b4f | 229 | printf " (master)" >expected && |
963c0407 SG |
230 | ( |
231 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 232 | __git_ps1 >"$actual" |
963c0407 SG |
233 | ) && |
234 | test_cmp expected "$actual" | |
235 | ' | |
236 | ||
237 | test_expect_success 'prompt - dirty status indicator - dirty worktree' ' | |
4fe00b4f SG |
238 | printf " (master *)" >expected && |
239 | echo "dirty" >file && | |
963c0407 SG |
240 | test_when_finished "git reset --hard" && |
241 | ( | |
242 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 243 | __git_ps1 >"$actual" |
963c0407 SG |
244 | ) && |
245 | test_cmp expected "$actual" | |
246 | ' | |
247 | ||
248 | test_expect_success 'prompt - dirty status indicator - dirty index' ' | |
4fe00b4f SG |
249 | printf " (master +)" >expected && |
250 | echo "dirty" >file && | |
963c0407 SG |
251 | test_when_finished "git reset --hard" && |
252 | git add -u && | |
253 | ( | |
254 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 255 | __git_ps1 >"$actual" |
963c0407 SG |
256 | ) && |
257 | test_cmp expected "$actual" | |
258 | ' | |
259 | ||
260 | test_expect_success 'prompt - dirty status indicator - dirty index and worktree' ' | |
4fe00b4f SG |
261 | printf " (master *+)" >expected && |
262 | echo "dirty index" >file && | |
963c0407 SG |
263 | test_when_finished "git reset --hard" && |
264 | git add -u && | |
4fe00b4f | 265 | echo "dirty worktree" >file && |
963c0407 SG |
266 | ( |
267 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 268 | __git_ps1 >"$actual" |
963c0407 SG |
269 | ) && |
270 | test_cmp expected "$actual" | |
271 | ' | |
272 | ||
a30d11eb SG |
273 | test_expect_success 'prompt - dirty status indicator - orphan branch - clean' ' |
274 | printf " (orphan #)" >expected && | |
275 | test_when_finished "git checkout master" && | |
276 | git checkout --orphan orphan && | |
277 | git reset --hard && | |
278 | ( | |
279 | GIT_PS1_SHOWDIRTYSTATE=y && | |
280 | __git_ps1 >"$actual" | |
281 | ) && | |
282 | test_cmp expected "$actual" | |
283 | ' | |
284 | ||
c26f70ce | 285 | test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' ' |
a30d11eb SG |
286 | printf " (orphan +)" >expected && |
287 | test_when_finished "git checkout master" && | |
288 | git checkout --orphan orphan && | |
289 | ( | |
290 | GIT_PS1_SHOWDIRTYSTATE=y && | |
291 | __git_ps1 >"$actual" | |
292 | ) && | |
293 | test_cmp expected "$actual" | |
294 | ' | |
295 | ||
c26f70ce | 296 | test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' ' |
a30d11eb SG |
297 | printf " (orphan *+)" >expected && |
298 | test_when_finished "git checkout master" && | |
299 | git checkout --orphan orphan && | |
300 | >file && | |
963c0407 SG |
301 | ( |
302 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 303 | __git_ps1 >"$actual" |
963c0407 SG |
304 | ) && |
305 | test_cmp expected "$actual" | |
306 | ' | |
307 | ||
dc7e7bce | 308 | test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' ' |
4fe00b4f SG |
309 | printf " (master)" >expected && |
310 | echo "dirty" >file && | |
963c0407 SG |
311 | test_when_finished "git reset --hard" && |
312 | test_config bash.showDirtyState false && | |
dc7e7bce MEW |
313 | ( |
314 | sane_unset GIT_PS1_SHOWDIRTYSTATE && | |
4fe00b4f | 315 | __git_ps1 >"$actual" |
dc7e7bce MEW |
316 | ) && |
317 | test_cmp expected "$actual" | |
318 | ' | |
319 | ||
320 | test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' ' | |
4fe00b4f SG |
321 | printf " (master)" >expected && |
322 | echo "dirty" >file && | |
dc7e7bce MEW |
323 | test_when_finished "git reset --hard" && |
324 | test_config bash.showDirtyState true && | |
325 | ( | |
326 | sane_unset GIT_PS1_SHOWDIRTYSTATE && | |
4fe00b4f | 327 | __git_ps1 >"$actual" |
dc7e7bce MEW |
328 | ) && |
329 | test_cmp expected "$actual" | |
330 | ' | |
331 | ||
332 | test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' ' | |
4fe00b4f SG |
333 | printf " (master)" >expected && |
334 | echo "dirty" >file && | |
dc7e7bce MEW |
335 | test_when_finished "git reset --hard" && |
336 | test_config bash.showDirtyState false && | |
337 | ( | |
338 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 339 | __git_ps1 >"$actual" |
dc7e7bce MEW |
340 | ) && |
341 | test_cmp expected "$actual" | |
342 | ' | |
343 | ||
344 | test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' ' | |
4fe00b4f SG |
345 | printf " (master *)" >expected && |
346 | echo "dirty" >file && | |
dc7e7bce MEW |
347 | test_when_finished "git reset --hard" && |
348 | test_config bash.showDirtyState true && | |
963c0407 SG |
349 | ( |
350 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 351 | __git_ps1 >"$actual" |
963c0407 SG |
352 | ) && |
353 | test_cmp expected "$actual" | |
354 | ' | |
355 | ||
356 | test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' ' | |
4fe00b4f SG |
357 | printf " (GIT_DIR!)" >expected && |
358 | echo "dirty" >file && | |
963c0407 SG |
359 | test_when_finished "git reset --hard" && |
360 | ( | |
361 | GIT_PS1_SHOWDIRTYSTATE=y && | |
362 | cd .git && | |
4fe00b4f | 363 | __git_ps1 >"$actual" |
963c0407 SG |
364 | ) && |
365 | test_cmp expected "$actual" | |
366 | ' | |
367 | ||
368 | test_expect_success 'prompt - stash status indicator - no stash' ' | |
4fe00b4f | 369 | printf " (master)" >expected && |
963c0407 SG |
370 | ( |
371 | GIT_PS1_SHOWSTASHSTATE=y && | |
4fe00b4f | 372 | __git_ps1 >"$actual" |
963c0407 SG |
373 | ) && |
374 | test_cmp expected "$actual" | |
375 | ' | |
376 | ||
377 | test_expect_success 'prompt - stash status indicator - stash' ' | |
4fe00b4f | 378 | printf " (master $)" >expected && |
963c0407 SG |
379 | echo 2 >file && |
380 | git stash && | |
381 | test_when_finished "git stash drop" && | |
dd0b72cb | 382 | git pack-refs --all && |
963c0407 SG |
383 | ( |
384 | GIT_PS1_SHOWSTASHSTATE=y && | |
4fe00b4f | 385 | __git_ps1 >"$actual" |
963c0407 SG |
386 | ) && |
387 | test_cmp expected "$actual" | |
388 | ' | |
389 | ||
390 | test_expect_success 'prompt - stash status indicator - not shown inside .git directory' ' | |
4fe00b4f | 391 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
392 | echo 2 >file && |
393 | git stash && | |
394 | test_when_finished "git stash drop" && | |
395 | ( | |
396 | GIT_PS1_SHOWSTASHSTATE=y && | |
397 | cd .git && | |
4fe00b4f | 398 | __git_ps1 >"$actual" |
963c0407 SG |
399 | ) && |
400 | test_cmp expected "$actual" | |
401 | ' | |
402 | ||
403 | test_expect_success 'prompt - untracked files status indicator - no untracked files' ' | |
4fe00b4f | 404 | printf " (master)" >expected && |
963c0407 SG |
405 | ( |
406 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
407 | cd otherrepo && | |
4fe00b4f | 408 | __git_ps1 >"$actual" |
963c0407 SG |
409 | ) && |
410 | test_cmp expected "$actual" | |
411 | ' | |
412 | ||
413 | test_expect_success 'prompt - untracked files status indicator - untracked files' ' | |
4fe00b4f | 414 | printf " (master %%)" >expected && |
963c0407 SG |
415 | ( |
416 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 417 | __git_ps1 >"$actual" |
6bfab998 SG |
418 | ) && |
419 | test_cmp expected "$actual" | |
420 | ' | |
421 | ||
422 | test_expect_success 'prompt - untracked files status indicator - empty untracked dir' ' | |
423 | printf " (master)" >expected && | |
424 | mkdir otherrepo/untracked-dir && | |
425 | test_when_finished "rm -rf otherrepo/untracked-dir" && | |
426 | ( | |
427 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
428 | cd otherrepo && | |
429 | __git_ps1 >"$actual" | |
430 | ) && | |
431 | test_cmp expected "$actual" | |
432 | ' | |
433 | ||
434 | test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' ' | |
435 | printf " (master %%)" >expected && | |
436 | mkdir otherrepo/untracked-dir && | |
437 | test_when_finished "rm -rf otherrepo/untracked-dir" && | |
438 | >otherrepo/untracked-dir/untracked-file && | |
439 | ( | |
440 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
441 | cd otherrepo && | |
442 | __git_ps1 >"$actual" | |
963c0407 SG |
443 | ) && |
444 | test_cmp expected "$actual" | |
445 | ' | |
446 | ||
9bdc5173 CT |
447 | test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' ' |
448 | printf " (master %%)" >expected && | |
449 | ( | |
450 | mkdir -p ignored_dir && | |
451 | cd ignored_dir && | |
452 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
453 | __git_ps1 >"$actual" | |
454 | ) && | |
455 | test_cmp expected "$actual" | |
456 | ' | |
457 | ||
58978e82 | 458 | test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' ' |
4fe00b4f | 459 | printf " (master)" >expected && |
58978e82 MEW |
460 | test_config bash.showUntrackedFiles false && |
461 | ( | |
462 | sane_unset GIT_PS1_SHOWUNTRACKEDFILES && | |
4fe00b4f | 463 | __git_ps1 >"$actual" |
58978e82 MEW |
464 | ) && |
465 | test_cmp expected "$actual" | |
466 | ' | |
467 | ||
468 | test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' ' | |
4fe00b4f | 469 | printf " (master)" >expected && |
58978e82 MEW |
470 | test_config bash.showUntrackedFiles true && |
471 | ( | |
472 | sane_unset GIT_PS1_SHOWUNTRACKEDFILES && | |
4fe00b4f | 473 | __git_ps1 >"$actual" |
58978e82 MEW |
474 | ) && |
475 | test_cmp expected "$actual" | |
476 | ' | |
477 | ||
478 | test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' ' | |
4fe00b4f | 479 | printf " (master)" >expected && |
58978e82 MEW |
480 | test_config bash.showUntrackedFiles false && |
481 | ( | |
482 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 483 | __git_ps1 >"$actual" |
58978e82 MEW |
484 | ) && |
485 | test_cmp expected "$actual" | |
486 | ' | |
487 | ||
488 | test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' ' | |
4fe00b4f | 489 | printf " (master %%)" >expected && |
58978e82 MEW |
490 | test_config bash.showUntrackedFiles true && |
491 | ( | |
492 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 493 | __git_ps1 >"$actual" |
58978e82 MEW |
494 | ) && |
495 | test_cmp expected "$actual" | |
496 | ' | |
497 | ||
963c0407 | 498 | test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' ' |
4fe00b4f | 499 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
500 | ( |
501 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
502 | cd .git && | |
4fe00b4f | 503 | __git_ps1 >"$actual" |
963c0407 SG |
504 | ) && |
505 | test_cmp expected "$actual" | |
506 | ' | |
507 | ||
508 | test_expect_success 'prompt - format string starting with dash' ' | |
4fe00b4f SG |
509 | printf -- "-master" >expected && |
510 | __git_ps1 "-%s" >"$actual" && | |
963c0407 SG |
511 | test_cmp expected "$actual" |
512 | ' | |
513 | ||
1572e18e | 514 | test_expect_success 'prompt - pc mode' ' |
8976500c | 515 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmaster" >expected && |
1572e18e EA |
516 | printf "" >expected_output && |
517 | ( | |
518 | __git_ps1 "BEFORE:" ":AFTER" >"$actual" && | |
519 | test_cmp expected_output "$actual" && | |
8976500c | 520 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
521 | ) && |
522 | test_cmp expected "$actual" | |
523 | ' | |
524 | ||
525 | test_expect_success 'prompt - bash color pc mode - branch name' ' | |
8976500c | 526 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
527 | ( |
528 | GIT_PS1_SHOWCOLORHINTS=y && | |
cff4243d | 529 | __git_ps1 "BEFORE:" ":AFTER" >"$actual" && |
8976500c | 530 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
531 | ) && |
532 | test_cmp expected "$actual" | |
533 | ' | |
534 | ||
535 | test_expect_success 'prompt - bash color pc mode - detached head' ' | |
8976500c | 536 | printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected && |
1572e18e EA |
537 | git checkout b1^ && |
538 | test_when_finished "git checkout master" && | |
539 | ( | |
540 | GIT_PS1_SHOWCOLORHINTS=y && | |
541 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 542 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
543 | ) && |
544 | test_cmp expected "$actual" | |
545 | ' | |
546 | ||
547 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' ' | |
8976500c | 548 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
549 | echo "dirty" >file && |
550 | test_when_finished "git reset --hard" && | |
551 | ( | |
552 | GIT_PS1_SHOWDIRTYSTATE=y && | |
553 | GIT_PS1_SHOWCOLORHINTS=y && | |
554 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 555 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
556 | ) && |
557 | test_cmp expected "$actual" | |
558 | ' | |
559 | ||
560 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' ' | |
8976500c | 561 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
562 | echo "dirty" >file && |
563 | test_when_finished "git reset --hard" && | |
564 | git add -u && | |
565 | ( | |
566 | GIT_PS1_SHOWDIRTYSTATE=y && | |
567 | GIT_PS1_SHOWCOLORHINTS=y && | |
568 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 569 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
570 | ) && |
571 | test_cmp expected "$actual" | |
572 | ' | |
573 | ||
574 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' ' | |
8976500c | 575 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
576 | echo "dirty index" >file && |
577 | test_when_finished "git reset --hard" && | |
578 | git add -u && | |
579 | echo "dirty worktree" >file && | |
580 | ( | |
581 | GIT_PS1_SHOWCOLORHINTS=y && | |
582 | GIT_PS1_SHOWDIRTYSTATE=y && | |
583 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 584 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
585 | ) && |
586 | test_cmp expected "$actual" | |
587 | ' | |
588 | ||
589 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' ' | |
8976500c | 590 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
591 | ( |
592 | GIT_PS1_SHOWDIRTYSTATE=y && | |
593 | GIT_PS1_SHOWCOLORHINTS=y && | |
594 | cd otherrepo && | |
595 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 596 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
597 | ) && |
598 | test_cmp expected "$actual" | |
599 | ' | |
600 | ||
601 | test_expect_success 'prompt - bash color pc mode - inside .git directory' ' | |
8976500c | 602 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected && |
1572e18e EA |
603 | echo "dirty" >file && |
604 | test_when_finished "git reset --hard" && | |
605 | ( | |
606 | GIT_PS1_SHOWDIRTYSTATE=y && | |
607 | GIT_PS1_SHOWCOLORHINTS=y && | |
608 | cd .git && | |
609 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 610 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
611 | ) && |
612 | test_cmp expected "$actual" | |
613 | ' | |
614 | ||
615 | test_expect_success 'prompt - bash color pc mode - stash status indicator' ' | |
8976500c | 616 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
617 | echo 2 >file && |
618 | git stash && | |
619 | test_when_finished "git stash drop" && | |
620 | ( | |
621 | GIT_PS1_SHOWSTASHSTATE=y && | |
622 | GIT_PS1_SHOWCOLORHINTS=y && | |
623 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 624 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
625 | ) && |
626 | test_cmp expected "$actual" | |
627 | ' | |
628 | ||
629 | test_expect_success 'prompt - bash color pc mode - untracked files status indicator' ' | |
8976500c | 630 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
631 | ( |
632 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
633 | GIT_PS1_SHOWCOLORHINTS=y && | |
634 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 635 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
636 | ) && |
637 | test_cmp expected "$actual" | |
638 | ' | |
639 | ||
f3bd62d0 | 640 | test_expect_success 'prompt - zsh color pc mode' ' |
1e4119c8 | 641 | printf "BEFORE: (%%F{green}master%%f):AFTER" >expected && |
1572e18e EA |
642 | ( |
643 | ZSH_VERSION=5.0.0 && | |
644 | GIT_PS1_SHOWCOLORHINTS=y && | |
1e4119c8 RH |
645 | __git_ps1 "BEFORE:" ":AFTER" && |
646 | printf "%s" "$PS1" >"$actual" | |
1572e18e EA |
647 | ) && |
648 | test_cmp expected "$actual" | |
649 | ' | |
650 | ||
0120b8c8 JA |
651 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' ' |
652 | printf " (master)" >expected && | |
653 | test_config bash.hideIfPwdIgnored false && | |
654 | ( | |
655 | cd ignored_dir && | |
656 | __git_ps1 >"$actual" | |
657 | ) && | |
658 | test_cmp expected "$actual" | |
659 | ' | |
660 | ||
661 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' ' | |
662 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && | |
663 | test_config bash.hideIfPwdIgnored false && | |
664 | ( | |
665 | cd ignored_dir && | |
666 | __git_ps1 "BEFORE:" ":AFTER" && | |
667 | printf "%s" "$PS1" >"$actual" | |
668 | ) && | |
669 | test_cmp expected "$actual" | |
670 | ' | |
671 | ||
672 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' ' | |
673 | printf " (master)" >expected && | |
674 | ( | |
675 | cd ignored_dir && | |
676 | __git_ps1 >"$actual" | |
677 | ) && | |
678 | test_cmp expected "$actual" | |
679 | ' | |
680 | ||
681 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' ' | |
682 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && | |
683 | ( | |
684 | cd ignored_dir && | |
685 | __git_ps1 "BEFORE:" ":AFTER" && | |
686 | printf "%s" "$PS1" >"$actual" | |
687 | ) && | |
688 | test_cmp expected "$actual" | |
689 | ' | |
690 | ||
691 | test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' ' | |
692 | printf " (master)" >expected && | |
693 | test_config bash.hideIfPwdIgnored false && | |
694 | ( | |
695 | cd ignored_dir && | |
696 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
697 | __git_ps1 >"$actual" | |
698 | ) && | |
699 | test_cmp expected "$actual" | |
700 | ' | |
701 | ||
702 | test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' ' | |
703 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && | |
704 | test_config bash.hideIfPwdIgnored false && | |
705 | ( | |
706 | cd ignored_dir && | |
707 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
708 | __git_ps1 "BEFORE:" ":AFTER" && | |
709 | printf "%s" "$PS1" >"$actual" | |
710 | ) && | |
711 | test_cmp expected "$actual" | |
712 | ' | |
713 | ||
714 | test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' ' | |
715 | printf "" >expected && | |
716 | ( | |
717 | cd ignored_dir && | |
718 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
719 | __git_ps1 >"$actual" | |
720 | ) && | |
721 | test_cmp expected "$actual" | |
722 | ' | |
723 | ||
724 | test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' ' | |
725 | printf "BEFORE::AFTER" >expected && | |
726 | ( | |
727 | cd ignored_dir && | |
728 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
729 | __git_ps1 "BEFORE:" ":AFTER" && | |
730 | printf "%s" "$PS1" >"$actual" | |
731 | ) && | |
732 | test_cmp expected "$actual" | |
733 | ' | |
734 | ||
d31f298f | 735 | test_expect_success 'prompt - hide if pwd ignored - inside gitdir' ' |
0120b8c8 JA |
736 | printf " (GIT_DIR!)" >expected && |
737 | ( | |
738 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
739 | cd .git && | |
d31f298f | 740 | __git_ps1 >"$actual" |
0120b8c8 JA |
741 | ) && |
742 | test_cmp expected "$actual" | |
743 | ' | |
744 | ||
963c0407 | 745 | test_done |