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