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