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