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