]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7512-status-help.sh
Merge branch 'ab/detox-gettext-tests'
[thirdparty/git.git] / t / t7512-status-help.sh
CommitLineData
70819263
LK
1#!/bin/sh
2#
3# Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas,
4# Thomas Nguy, Khoi Nguyen
5# Grenoble INP Ensimag
6#
7
4f021b34 8test_description='git status advice'
70819263 9
1e2ae142 10GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
11export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12
70819263
LK
13. ./test-lib.sh
14
15. "$TEST_DIRECTORY"/lib-rebase.sh
16
17set_fake_editor
18
19test_expect_success 'prepare for conflicts' '
6a38ef2c 20 git config --global advice.statusuoption false &&
70819263
LK
21 test_commit init main.txt init &&
22 git branch conflicts &&
1e2ae142 23 test_commit on_main main.txt on_main &&
70819263
LK
24 git checkout conflicts &&
25 test_commit on_conflicts main.txt on_conflicts
26'
27
28
29test_expect_success 'status when conflicts unresolved' '
1e2ae142 30 test_must_fail git merge main &&
1c7969c9
MM
31 cat >expected <<\EOF &&
32On branch conflicts
33You have unmerged paths.
34 (fix conflicts and run "git commit")
b0a61ab2 35 (use "git merge --abort" to abort the merge)
1c7969c9
MM
36
37Unmerged paths:
38 (use "git add <file>..." to mark resolution)
c7cb333f 39 both modified: main.txt
1c7969c9
MM
40
41no changes added to commit (use "git add" and/or "git commit -a")
42EOF
70819263 43 git status --untracked-files=no >actual &&
1108cea7 44 test_cmp expected actual
70819263
LK
45'
46
47
48test_expect_success 'status when conflicts resolved before commit' '
49 git reset --hard conflicts &&
1e2ae142 50 test_must_fail git merge main &&
70819263
LK
51 echo one >main.txt &&
52 git add main.txt &&
1c7969c9
MM
53 cat >expected <<\EOF &&
54On branch conflicts
55All conflicts fixed but you are still merging.
56 (use "git commit" to conclude merge)
57
58Changes to be committed:
1c7969c9
MM
59 modified: main.txt
60
61Untracked files not listed (use -u option to show untracked files)
62EOF
70819263 63 git status --untracked-files=no >actual &&
1108cea7 64 test_cmp expected actual
70819263
LK
65'
66
67
68test_expect_success 'prepare for rebase conflicts' '
1e2ae142 69 git reset --hard main &&
70819263
LK
70 git checkout -b rebase_conflicts &&
71 test_commit one_rebase main.txt one &&
72 test_commit two_rebase main.txt two &&
73 test_commit three_rebase main.txt three
74'
75
76
10cdb9f3 77test_expect_success 'status when rebase --apply in progress before resolving conflicts' '
70819263 78 test_when_finished "git rebase --abort" &&
0722c805 79 ONTO=$(git rev-parse --short HEAD^^) &&
10cdb9f3 80 test_must_fail git rebase --apply HEAD^ --onto HEAD^^ &&
1c7969c9
MM
81 cat >expected <<EOF &&
82rebase in progress; onto $ONTO
83You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
84 (fix conflicts and then run "git rebase --continue")
85 (use "git rebase --skip" to skip this patch)
86 (use "git rebase --abort" to check out the original branch)
87
88Unmerged paths:
80f537f7 89 (use "git restore --staged <file>..." to unstage)
1c7969c9 90 (use "git add <file>..." to mark resolution)
c7cb333f 91 both modified: main.txt
1c7969c9
MM
92
93no changes added to commit (use "git add" and/or "git commit -a")
94EOF
70819263 95 git status --untracked-files=no >actual &&
1108cea7 96 test_cmp expected actual
70819263
LK
97'
98
99
10cdb9f3 100test_expect_success 'status when rebase --apply in progress before rebase --continue' '
70819263
LK
101 git reset --hard rebase_conflicts &&
102 test_when_finished "git rebase --abort" &&
0722c805 103 ONTO=$(git rev-parse --short HEAD^^) &&
10cdb9f3 104 test_must_fail git rebase --apply HEAD^ --onto HEAD^^ &&
70819263
LK
105 echo three >main.txt &&
106 git add main.txt &&
1c7969c9
MM
107 cat >expected <<EOF &&
108rebase in progress; onto $ONTO
109You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
110 (all conflicts fixed: run "git rebase --continue")
111
112Changes to be committed:
80f537f7 113 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
114 modified: main.txt
115
116Untracked files not listed (use -u option to show untracked files)
117EOF
70819263 118 git status --untracked-files=no >actual &&
1108cea7 119 test_cmp expected actual
70819263
LK
120'
121
122
123test_expect_success 'prepare for rebase_i_conflicts' '
1e2ae142 124 git reset --hard main &&
70819263
LK
125 git checkout -b rebase_i_conflicts &&
126 test_commit one_unmerge main.txt one_unmerge &&
127 git branch rebase_i_conflicts_second &&
1e2ae142 128 test_commit one_main main.txt one_main &&
70819263
LK
129 git checkout rebase_i_conflicts_second &&
130 test_commit one_second main.txt one_second
131'
132
133
134test_expect_success 'status during rebase -i when conflicts unresolved' '
135 test_when_finished "git rebase --abort" &&
0722c805 136 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
84e6fb9d 137 LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) &&
70819263 138 test_must_fail git rebase -i rebase_i_conflicts &&
1c7969c9 139 cat >expected <<EOF &&
df25e947 140interactive rebase in progress; onto $ONTO
84e6fb9d
GP
141Last command done (1 command done):
142 pick $LAST_COMMIT one_second
143No commands remaining.
1c7969c9
MM
144You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
145 (fix conflicts and then run "git rebase --continue")
146 (use "git rebase --skip" to skip this patch)
147 (use "git rebase --abort" to check out the original branch)
148
149Unmerged paths:
80f537f7 150 (use "git restore --staged <file>..." to unstage)
1c7969c9 151 (use "git add <file>..." to mark resolution)
c7cb333f 152 both modified: main.txt
1c7969c9
MM
153
154no changes added to commit (use "git add" and/or "git commit -a")
155EOF
70819263 156 git status --untracked-files=no >actual &&
1108cea7 157 test_cmp expected actual
70819263
LK
158'
159
160
161test_expect_success 'status during rebase -i after resolving conflicts' '
162 git reset --hard rebase_i_conflicts_second &&
163 test_when_finished "git rebase --abort" &&
0722c805 164 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
84e6fb9d 165 LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) &&
70819263
LK
166 test_must_fail git rebase -i rebase_i_conflicts &&
167 git add main.txt &&
1c7969c9 168 cat >expected <<EOF &&
df25e947 169interactive rebase in progress; onto $ONTO
84e6fb9d
GP
170Last command done (1 command done):
171 pick $LAST_COMMIT one_second
172No commands remaining.
1c7969c9
MM
173You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
174 (all conflicts fixed: run "git rebase --continue")
175
176Changes to be committed:
80f537f7 177 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
178 modified: main.txt
179
180Untracked files not listed (use -u option to show untracked files)
181EOF
70819263 182 git status --untracked-files=no >actual &&
1108cea7 183 test_cmp expected actual
70819263
LK
184'
185
186
187test_expect_success 'status when rebasing -i in edit mode' '
1e2ae142 188 git reset --hard main &&
70819263
LK
189 git checkout -b rebase_i_edit &&
190 test_commit one_rebase_i main.txt one &&
191 test_commit two_rebase_i main.txt two &&
84e6fb9d 192 COMMIT2=$(git rev-parse --short rebase_i_edit) &&
70819263 193 test_commit three_rebase_i main.txt three &&
84e6fb9d 194 COMMIT3=$(git rev-parse --short rebase_i_edit) &&
70819263
LK
195 FAKE_LINES="1 edit 2" &&
196 export FAKE_LINES &&
197 test_when_finished "git rebase --abort" &&
0722c805 198 ONTO=$(git rev-parse --short HEAD~2) &&
70819263 199 git rebase -i HEAD~2 &&
1c7969c9 200 cat >expected <<EOF &&
df25e947 201interactive rebase in progress; onto $ONTO
84e6fb9d
GP
202Last commands done (2 commands done):
203 pick $COMMIT2 two_rebase_i
204 edit $COMMIT3 three_rebase_i
205No commands remaining.
1c7969c9
MM
206You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
207 (use "git commit --amend" to amend the current commit)
208 (use "git rebase --continue" once you are satisfied with your changes)
209
210nothing to commit (use -u to show untracked files)
211EOF
70819263 212 git status --untracked-files=no >actual &&
1108cea7 213 test_cmp expected actual
70819263
LK
214'
215
216
2d1cceba 217test_expect_success 'status when splitting a commit' '
1e2ae142 218 git reset --hard main &&
2d1cceba
LK
219 git checkout -b split_commit &&
220 test_commit one_split main.txt one &&
221 test_commit two_split main.txt two &&
84e6fb9d 222 COMMIT2=$(git rev-parse --short split_commit) &&
2d1cceba 223 test_commit three_split main.txt three &&
84e6fb9d 224 COMMIT3=$(git rev-parse --short split_commit) &&
2d1cceba 225 test_commit four_split main.txt four &&
84e6fb9d 226 COMMIT4=$(git rev-parse --short split_commit) &&
2d1cceba
LK
227 FAKE_LINES="1 edit 2 3" &&
228 export FAKE_LINES &&
229 test_when_finished "git rebase --abort" &&
0722c805 230 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
231 git rebase -i HEAD~3 &&
232 git reset HEAD^ &&
1c7969c9 233 cat >expected <<EOF &&
df25e947 234interactive rebase in progress; onto $ONTO
84e6fb9d
GP
235Last commands done (2 commands done):
236 pick $COMMIT2 two_split
237 edit $COMMIT3 three_split
238Next command to do (1 remaining command):
239 pick $COMMIT4 four_split
240 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
241You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
242 (Once your working directory is clean, run "git rebase --continue")
243
244Changes not staged for commit:
245 (use "git add <file>..." to update what will be committed)
80f537f7 246 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
247 modified: main.txt
248
249no changes added to commit (use "git add" and/or "git commit -a")
250EOF
2d1cceba 251 git status --untracked-files=no >actual &&
1108cea7 252 test_cmp expected actual
2d1cceba
LK
253'
254
255
256test_expect_success 'status after editing the last commit with --amend during a rebase -i' '
1e2ae142 257 git reset --hard main &&
2d1cceba
LK
258 git checkout -b amend_last &&
259 test_commit one_amend main.txt one &&
260 test_commit two_amend main.txt two &&
261 test_commit three_amend main.txt three &&
84e6fb9d 262 COMMIT3=$(git rev-parse --short amend_last) &&
2d1cceba 263 test_commit four_amend main.txt four &&
84e6fb9d 264 COMMIT4=$(git rev-parse --short amend_last) &&
2d1cceba
LK
265 FAKE_LINES="1 2 edit 3" &&
266 export FAKE_LINES &&
267 test_when_finished "git rebase --abort" &&
0722c805 268 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
269 git rebase -i HEAD~3 &&
270 git commit --amend -m "foo" &&
1c7969c9 271 cat >expected <<EOF &&
df25e947 272interactive rebase in progress; onto $ONTO
84e6fb9d
GP
273Last commands done (3 commands done):
274 pick $COMMIT3 three_amend
275 edit $COMMIT4 four_amend
276 (see more in file .git/rebase-merge/done)
277No commands remaining.
1c7969c9
MM
278You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
279 (use "git commit --amend" to amend the current commit)
280 (use "git rebase --continue" once you are satisfied with your changes)
281
282nothing to commit (use -u to show untracked files)
283EOF
2d1cceba 284 git status --untracked-files=no >actual &&
1108cea7 285 test_cmp expected actual
2d1cceba
LK
286'
287
288
289test_expect_success 'prepare for several edits' '
1e2ae142 290 git reset --hard main &&
2d1cceba
LK
291 git checkout -b several_edits &&
292 test_commit one_edits main.txt one &&
293 test_commit two_edits main.txt two &&
294 test_commit three_edits main.txt three &&
295 test_commit four_edits main.txt four
296'
297
298
299test_expect_success 'status: (continue first edit) second edit' '
300 FAKE_LINES="edit 1 edit 2 3" &&
301 export FAKE_LINES &&
302 test_when_finished "git rebase --abort" &&
84e6fb9d
GP
303 COMMIT2=$(git rev-parse --short several_edits^^) &&
304 COMMIT3=$(git rev-parse --short several_edits^) &&
305 COMMIT4=$(git rev-parse --short several_edits) &&
0722c805 306 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
307 git rebase -i HEAD~3 &&
308 git rebase --continue &&
1c7969c9 309 cat >expected <<EOF &&
df25e947 310interactive rebase in progress; onto $ONTO
84e6fb9d
GP
311Last commands done (2 commands done):
312 edit $COMMIT2 two_edits
313 edit $COMMIT3 three_edits
314Next command to do (1 remaining command):
315 pick $COMMIT4 four_edits
316 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
317You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
318 (use "git commit --amend" to amend the current commit)
319 (use "git rebase --continue" once you are satisfied with your changes)
320
321nothing to commit (use -u to show untracked files)
322EOF
2d1cceba 323 git status --untracked-files=no >actual &&
1108cea7 324 test_cmp expected actual
2d1cceba
LK
325'
326
327
328test_expect_success 'status: (continue first edit) second edit and split' '
329 git reset --hard several_edits &&
330 FAKE_LINES="edit 1 edit 2 3" &&
331 export FAKE_LINES &&
332 test_when_finished "git rebase --abort" &&
84e6fb9d
GP
333 COMMIT2=$(git rev-parse --short several_edits^^) &&
334 COMMIT3=$(git rev-parse --short several_edits^) &&
335 COMMIT4=$(git rev-parse --short several_edits) &&
0722c805 336 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
337 git rebase -i HEAD~3 &&
338 git rebase --continue &&
339 git reset HEAD^ &&
1c7969c9 340 cat >expected <<EOF &&
df25e947 341interactive rebase in progress; onto $ONTO
84e6fb9d
GP
342Last commands done (2 commands done):
343 edit $COMMIT2 two_edits
344 edit $COMMIT3 three_edits
345Next command to do (1 remaining command):
346 pick $COMMIT4 four_edits
347 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
348You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
349 (Once your working directory is clean, run "git rebase --continue")
350
351Changes not staged for commit:
352 (use "git add <file>..." to update what will be committed)
80f537f7 353 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
354 modified: main.txt
355
356no changes added to commit (use "git add" and/or "git commit -a")
357EOF
2d1cceba 358 git status --untracked-files=no >actual &&
1108cea7 359 test_cmp expected actual
2d1cceba
LK
360'
361
362
363test_expect_success 'status: (continue first edit) second edit and amend' '
364 git reset --hard several_edits &&
365 FAKE_LINES="edit 1 edit 2 3" &&
366 export FAKE_LINES &&
367 test_when_finished "git rebase --abort" &&
84e6fb9d
GP
368 COMMIT2=$(git rev-parse --short several_edits^^) &&
369 COMMIT3=$(git rev-parse --short several_edits^) &&
370 COMMIT4=$(git rev-parse --short several_edits) &&
0722c805 371 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
372 git rebase -i HEAD~3 &&
373 git rebase --continue &&
374 git commit --amend -m "foo" &&
1c7969c9 375 cat >expected <<EOF &&
df25e947 376interactive rebase in progress; onto $ONTO
84e6fb9d
GP
377Last commands done (2 commands done):
378 edit $COMMIT2 two_edits
379 edit $COMMIT3 three_edits
380Next command to do (1 remaining command):
381 pick $COMMIT4 four_edits
382 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
383You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
384 (use "git commit --amend" to amend the current commit)
385 (use "git rebase --continue" once you are satisfied with your changes)
386
387nothing to commit (use -u to show untracked files)
388EOF
2d1cceba 389 git status --untracked-files=no >actual &&
1108cea7 390 test_cmp expected actual
2d1cceba
LK
391'
392
393
394test_expect_success 'status: (amend first edit) second edit' '
395 git reset --hard several_edits &&
396 FAKE_LINES="edit 1 edit 2 3" &&
397 export FAKE_LINES &&
398 test_when_finished "git rebase --abort" &&
84e6fb9d
GP
399 COMMIT2=$(git rev-parse --short several_edits^^) &&
400 COMMIT3=$(git rev-parse --short several_edits^) &&
401 COMMIT4=$(git rev-parse --short several_edits) &&
0722c805 402 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
403 git rebase -i HEAD~3 &&
404 git commit --amend -m "a" &&
405 git rebase --continue &&
1c7969c9 406 cat >expected <<EOF &&
df25e947 407interactive rebase in progress; onto $ONTO
84e6fb9d
GP
408Last commands done (2 commands done):
409 edit $COMMIT2 two_edits
410 edit $COMMIT3 three_edits
411Next command to do (1 remaining command):
412 pick $COMMIT4 four_edits
413 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
414You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
415 (use "git commit --amend" to amend the current commit)
416 (use "git rebase --continue" once you are satisfied with your changes)
417
418nothing to commit (use -u to show untracked files)
419EOF
2d1cceba 420 git status --untracked-files=no >actual &&
1108cea7 421 test_cmp expected actual
2d1cceba
LK
422'
423
424
425test_expect_success 'status: (amend first edit) second edit and split' '
426 git reset --hard several_edits &&
427 FAKE_LINES="edit 1 edit 2 3" &&
428 export FAKE_LINES &&
429 test_when_finished "git rebase --abort" &&
0722c805 430 ONTO=$(git rev-parse --short HEAD~3) &&
84e6fb9d
GP
431 COMMIT2=$(git rev-parse --short several_edits^^) &&
432 COMMIT3=$(git rev-parse --short several_edits^) &&
433 COMMIT4=$(git rev-parse --short several_edits) &&
2d1cceba
LK
434 git rebase -i HEAD~3 &&
435 git commit --amend -m "b" &&
436 git rebase --continue &&
437 git reset HEAD^ &&
1c7969c9 438 cat >expected <<EOF &&
df25e947 439interactive rebase in progress; onto $ONTO
84e6fb9d
GP
440Last commands done (2 commands done):
441 edit $COMMIT2 two_edits
442 edit $COMMIT3 three_edits
443Next command to do (1 remaining command):
444 pick $COMMIT4 four_edits
445 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
446You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
447 (Once your working directory is clean, run "git rebase --continue")
448
449Changes not staged for commit:
450 (use "git add <file>..." to update what will be committed)
80f537f7 451 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
452 modified: main.txt
453
454no changes added to commit (use "git add" and/or "git commit -a")
455EOF
2d1cceba 456 git status --untracked-files=no >actual &&
1108cea7 457 test_cmp expected actual
2d1cceba
LK
458'
459
460
461test_expect_success 'status: (amend first edit) second edit and amend' '
462 git reset --hard several_edits &&
463 FAKE_LINES="edit 1 edit 2 3" &&
464 export FAKE_LINES &&
465 test_when_finished "git rebase --abort" &&
84e6fb9d
GP
466 COMMIT2=$(git rev-parse --short several_edits^^) &&
467 COMMIT3=$(git rev-parse --short several_edits^) &&
468 COMMIT4=$(git rev-parse --short several_edits) &&
0722c805 469 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
470 git rebase -i HEAD~3 &&
471 git commit --amend -m "c" &&
472 git rebase --continue &&
473 git commit --amend -m "d" &&
1c7969c9 474 cat >expected <<EOF &&
df25e947 475interactive rebase in progress; onto $ONTO
84e6fb9d
GP
476Last commands done (2 commands done):
477 edit $COMMIT2 two_edits
478 edit $COMMIT3 three_edits
479Next command to do (1 remaining command):
480 pick $COMMIT4 four_edits
481 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
482You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
483 (use "git commit --amend" to amend the current commit)
484 (use "git rebase --continue" once you are satisfied with your changes)
485
486nothing to commit (use -u to show untracked files)
487EOF
2d1cceba 488 git status --untracked-files=no >actual &&
1108cea7 489 test_cmp expected actual
2d1cceba
LK
490'
491
492
493test_expect_success 'status: (split first edit) second edit' '
494 git reset --hard several_edits &&
495 FAKE_LINES="edit 1 edit 2 3" &&
496 export FAKE_LINES &&
497 test_when_finished "git rebase --abort" &&
84e6fb9d
GP
498 COMMIT2=$(git rev-parse --short several_edits^^) &&
499 COMMIT3=$(git rev-parse --short several_edits^) &&
500 COMMIT4=$(git rev-parse --short several_edits) &&
0722c805 501 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
502 git rebase -i HEAD~3 &&
503 git reset HEAD^ &&
504 git add main.txt &&
505 git commit -m "e" &&
506 git rebase --continue &&
1c7969c9 507 cat >expected <<EOF &&
df25e947 508interactive rebase in progress; onto $ONTO
84e6fb9d
GP
509Last commands done (2 commands done):
510 edit $COMMIT2 two_edits
511 edit $COMMIT3 three_edits
512Next command to do (1 remaining command):
513 pick $COMMIT4 four_edits
514 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
515You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
516 (use "git commit --amend" to amend the current commit)
517 (use "git rebase --continue" once you are satisfied with your changes)
518
519nothing to commit (use -u to show untracked files)
520EOF
2d1cceba 521 git status --untracked-files=no >actual &&
1108cea7 522 test_cmp expected actual
2d1cceba
LK
523'
524
525
526test_expect_success 'status: (split first edit) second edit and split' '
527 git reset --hard several_edits &&
528 FAKE_LINES="edit 1 edit 2 3" &&
529 export FAKE_LINES &&
530 test_when_finished "git rebase --abort" &&
84e6fb9d
GP
531 COMMIT2=$(git rev-parse --short several_edits^^) &&
532 COMMIT3=$(git rev-parse --short several_edits^) &&
533 COMMIT4=$(git rev-parse --short several_edits) &&
0722c805 534 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
535 git rebase -i HEAD~3 &&
536 git reset HEAD^ &&
537 git add main.txt &&
538 git commit --amend -m "f" &&
539 git rebase --continue &&
540 git reset HEAD^ &&
1c7969c9 541 cat >expected <<EOF &&
df25e947 542interactive rebase in progress; onto $ONTO
84e6fb9d
GP
543Last commands done (2 commands done):
544 edit $COMMIT2 two_edits
545 edit $COMMIT3 three_edits
546Next command to do (1 remaining command):
547 pick $COMMIT4 four_edits
548 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
549You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
550 (Once your working directory is clean, run "git rebase --continue")
551
552Changes not staged for commit:
553 (use "git add <file>..." to update what will be committed)
80f537f7 554 (use "git restore <file>..." to discard changes in working directory)
1c7969c9
MM
555 modified: main.txt
556
557no changes added to commit (use "git add" and/or "git commit -a")
558EOF
2d1cceba 559 git status --untracked-files=no >actual &&
1108cea7 560 test_cmp expected actual
2d1cceba
LK
561'
562
563
564test_expect_success 'status: (split first edit) second edit and amend' '
565 git reset --hard several_edits &&
566 FAKE_LINES="edit 1 edit 2 3" &&
567 export FAKE_LINES &&
568 test_when_finished "git rebase --abort" &&
84e6fb9d
GP
569 COMMIT2=$(git rev-parse --short several_edits^^) &&
570 COMMIT3=$(git rev-parse --short several_edits^) &&
571 COMMIT4=$(git rev-parse --short several_edits) &&
0722c805 572 ONTO=$(git rev-parse --short HEAD~3) &&
2d1cceba
LK
573 git rebase -i HEAD~3 &&
574 git reset HEAD^ &&
575 git add main.txt &&
576 git commit --amend -m "g" &&
577 git rebase --continue &&
578 git commit --amend -m "h" &&
1c7969c9 579 cat >expected <<EOF &&
df25e947 580interactive rebase in progress; onto $ONTO
84e6fb9d
GP
581Last commands done (2 commands done):
582 edit $COMMIT2 two_edits
583 edit $COMMIT3 three_edits
584Next command to do (1 remaining command):
585 pick $COMMIT4 four_edits
586 (use "git rebase --edit-todo" to view and edit)
1c7969c9
MM
587You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
588 (use "git commit --amend" to amend the current commit)
589 (use "git rebase --continue" once you are satisfied with your changes)
590
591nothing to commit (use -u to show untracked files)
592EOF
2d1cceba 593 git status --untracked-files=no >actual &&
1108cea7 594 test_cmp expected actual
2d1cceba
LK
595'
596
597
70819263 598test_expect_success 'prepare am_session' '
1e2ae142 599 git reset --hard main &&
70819263
LK
600 git checkout -b am_session &&
601 test_commit one_am one.txt "one" &&
602 test_commit two_am two.txt "two" &&
603 test_commit three_am three.txt "three"
604'
605
606
607test_expect_success 'status in an am session: file already exists' '
608 git checkout -b am_already_exists &&
609 test_when_finished "rm Maildir/* && git am --abort" &&
610 git format-patch -1 -oMaildir &&
611 test_must_fail git am Maildir/*.patch &&
1c7969c9
MM
612 cat >expected <<\EOF &&
613On branch am_already_exists
614You are in the middle of an am session.
615 (fix conflicts and then run "git am --continue")
616 (use "git am --skip" to skip this patch)
617 (use "git am --abort" to restore the original branch)
618
619nothing to commit (use -u to show untracked files)
620EOF
70819263 621 git status --untracked-files=no >actual &&
1108cea7 622 test_cmp expected actual
70819263
LK
623'
624
625
626test_expect_success 'status in an am session: file does not exist' '
627 git reset --hard am_session &&
628 git checkout -b am_not_exists &&
629 git rm three.txt &&
630 git commit -m "delete three.txt" &&
631 test_when_finished "rm Maildir/* && git am --abort" &&
632 git format-patch -1 -oMaildir &&
633 test_must_fail git am Maildir/*.patch &&
1c7969c9
MM
634 cat >expected <<\EOF &&
635On branch am_not_exists
636You are in the middle of an am session.
637 (fix conflicts and then run "git am --continue")
638 (use "git am --skip" to skip this patch)
639 (use "git am --abort" to restore the original branch)
640
641nothing to commit (use -u to show untracked files)
642EOF
70819263 643 git status --untracked-files=no >actual &&
1108cea7 644 test_cmp expected actual
70819263
LK
645'
646
647
648test_expect_success 'status in an am session: empty patch' '
649 git reset --hard am_session &&
650 git checkout -b am_empty &&
651 test_when_finished "rm Maildir/* && git am --abort" &&
652 git format-patch -3 -oMaildir &&
653 git rm one.txt two.txt three.txt &&
654 git commit -m "delete all am_empty" &&
655 echo error >Maildir/0002-two_am.patch &&
656 test_must_fail git am Maildir/*.patch &&
1c7969c9
MM
657 cat >expected <<\EOF &&
658On branch am_empty
659You are in the middle of an am session.
660The current patch is empty.
661 (use "git am --skip" to skip this patch)
662 (use "git am --abort" to restore the original branch)
663
664nothing to commit (use -u to show untracked files)
665EOF
70819263 666 git status --untracked-files=no >actual &&
1108cea7 667 test_cmp expected actual
70819263
LK
668'
669
670
671test_expect_success 'status when bisecting' '
1e2ae142 672 git reset --hard main &&
70819263
LK
673 git checkout -b bisect &&
674 test_commit one_bisect main.txt one &&
675 test_commit two_bisect main.txt two &&
676 test_commit three_bisect main.txt three &&
677 test_when_finished "git bisect reset" &&
678 git bisect start &&
679 git bisect bad &&
680 git bisect good one_bisect &&
b397ea48 681 TGT=$(git rev-parse --short two_bisect) &&
1c7969c9
MM
682 cat >expected <<EOF &&
683HEAD detached at $TGT
684You are currently bisecting, started from branch '\''bisect'\''.
685 (use "git bisect reset" to get back to the original branch)
686
687nothing to commit (use -u to show untracked files)
688EOF
70819263 689 git status --untracked-files=no >actual &&
1108cea7 690 test_cmp expected actual
70819263
LK
691'
692
693
10cdb9f3 694test_expect_success 'status when rebase --apply conflicts with statushints disabled' '
1e2ae142 695 git reset --hard main &&
70819263
LK
696 git checkout -b statushints_disabled &&
697 test_when_finished "git config --local advice.statushints true" &&
698 git config --local advice.statushints false &&
699 test_commit one_statushints main.txt one &&
700 test_commit two_statushints main.txt two &&
701 test_commit three_statushints main.txt three &&
702 test_when_finished "git rebase --abort" &&
0722c805 703 ONTO=$(git rev-parse --short HEAD^^) &&
10cdb9f3 704 test_must_fail git rebase --apply HEAD^ --onto HEAD^^ &&
1c7969c9
MM
705 cat >expected <<EOF &&
706rebase in progress; onto $ONTO
707You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
708
709Unmerged paths:
c7cb333f 710 both modified: main.txt
1c7969c9
MM
711
712no changes added to commit
713EOF
70819263 714 git status --untracked-files=no >actual &&
1108cea7 715 test_cmp expected actual
70819263
LK
716'
717
718
719test_expect_success 'prepare for cherry-pick conflicts' '
1e2ae142 720 git reset --hard main &&
70819263
LK
721 git checkout -b cherry_branch &&
722 test_commit one_cherry main.txt one &&
723 test_commit two_cherries main.txt two &&
724 git checkout -b cherry_branch_second &&
725 test_commit second_cherry main.txt second &&
726 git checkout cherry_branch &&
727 test_commit three_cherries main.txt three
728'
729
730
731test_expect_success 'status when cherry-picking before resolving conflicts' '
732 test_when_finished "git cherry-pick --abort" &&
733 test_must_fail git cherry-pick cherry_branch_second &&
bffd8098
RT
734 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
735 cat >expected <<EOF &&
1c7969c9 736On branch cherry_branch
bffd8098 737You are currently cherry-picking commit $TO_CHERRY_PICK.
1c7969c9 738 (fix conflicts and run "git cherry-pick --continue")
86ae43da 739 (use "git cherry-pick --skip" to skip this patch)
1c7969c9
MM
740 (use "git cherry-pick --abort" to cancel the cherry-pick operation)
741
742Unmerged paths:
743 (use "git add <file>..." to mark resolution)
c7cb333f 744 both modified: main.txt
1c7969c9
MM
745
746no changes added to commit (use "git add" and/or "git commit -a")
747EOF
70819263 748 git status --untracked-files=no >actual &&
1108cea7 749 test_cmp expected actual
70819263
LK
750'
751
752
753test_expect_success 'status when cherry-picking after resolving conflicts' '
754 git reset --hard cherry_branch &&
755 test_when_finished "git cherry-pick --abort" &&
756 test_must_fail git cherry-pick cherry_branch_second &&
bffd8098 757 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
70819263
LK
758 echo end >main.txt &&
759 git add main.txt &&
bffd8098 760 cat >expected <<EOF &&
1c7969c9 761On branch cherry_branch
bffd8098 762You are currently cherry-picking commit $TO_CHERRY_PICK.
1c7969c9 763 (all conflicts fixed: run "git cherry-pick --continue")
86ae43da 764 (use "git cherry-pick --skip" to skip this patch)
1c7969c9
MM
765 (use "git cherry-pick --abort" to cancel the cherry-pick operation)
766
767Changes to be committed:
1c7969c9
MM
768 modified: main.txt
769
770Untracked files not listed (use -u option to show untracked files)
771EOF
70819263 772 git status --untracked-files=no >actual &&
1108cea7 773 test_cmp expected actual
70819263
LK
774'
775
4a72486d
PW
776test_expect_success 'status when cherry-picking after committing conflict resolution' '
777 git reset --hard cherry_branch &&
778 test_when_finished "git cherry-pick --abort" &&
779 test_must_fail git cherry-pick cherry_branch_second one_cherry &&
780 echo end >main.txt &&
781 git commit -a &&
782 cat >expected <<EOF &&
783On branch cherry_branch
784Cherry-pick currently in progress.
785 (run "git cherry-pick --continue" to continue)
86ae43da 786 (use "git cherry-pick --skip" to skip this patch)
4a72486d
PW
787 (use "git cherry-pick --abort" to cancel the cherry-pick operation)
788
789nothing to commit (use -u to show untracked files)
790EOF
791 git status --untracked-files=no >actual &&
1108cea7 792 test_cmp expected actual
4a72486d
PW
793'
794
ed5b1ca1
PW
795test_expect_success 'status shows cherry-pick with invalid oid' '
796 mkdir .git/sequencer &&
797 test_write_lines "pick invalid-oid" >.git/sequencer/todo &&
798 git status --untracked-files=no >actual 2>err &&
799 git cherry-pick --quit &&
800 test_must_be_empty err &&
1108cea7 801 test_cmp expected actual
ed5b1ca1
PW
802'
803
804test_expect_success 'status does not show error if .git/sequencer is a file' '
805 test_when_finished "rm .git/sequencer" &&
806 test_write_lines hello >.git/sequencer &&
807 git status --untracked-files=no 2>err &&
808 test_must_be_empty err
809'
810
46ab7d46 811test_expect_success 'status showing detached at and from a tag' '
b397ea48
NTND
812 test_commit atag tagging &&
813 git checkout atag &&
59c22205 814 cat >expected <<\EOF &&
1c7969c9
MM
815HEAD detached at atag
816nothing to commit (use -u to show untracked files)
817EOF
b397ea48 818 git status --untracked-files=no >actual &&
1108cea7 819 test_cmp expected actual &&
46ab7d46
JH
820
821 git reset --hard HEAD^ &&
59c22205 822 cat >expected <<\EOF &&
1c7969c9
MM
823HEAD detached from atag
824nothing to commit (use -u to show untracked files)
825EOF
46ab7d46 826 git status --untracked-files=no >actual &&
1108cea7 827 test_cmp expected actual
b397ea48 828'
70819263 829
db4ef449 830test_expect_success 'status while reverting commit (conflicts)' '
1e2ae142 831 git checkout main &&
db4ef449
MM
832 echo before >to-revert.txt &&
833 test_commit before to-revert.txt &&
834 echo old >to-revert.txt &&
835 test_commit old to-revert.txt &&
836 echo new >to-revert.txt &&
837 test_commit new to-revert.txt &&
87e139c0
MM
838 TO_REVERT=$(git rev-parse --short HEAD^) &&
839 test_must_fail git revert $TO_REVERT &&
59c22205 840 cat >expected <<EOF &&
1e2ae142 841On branch main
1c7969c9
MM
842You are currently reverting commit $TO_REVERT.
843 (fix conflicts and run "git revert --continue")
86ae43da 844 (use "git revert --skip" to skip this patch)
1c7969c9
MM
845 (use "git revert --abort" to cancel the revert operation)
846
847Unmerged paths:
80f537f7 848 (use "git restore --staged <file>..." to unstage)
1c7969c9 849 (use "git add <file>..." to mark resolution)
c7cb333f 850 both modified: to-revert.txt
1c7969c9
MM
851
852no changes added to commit (use "git add" and/or "git commit -a")
853EOF
db4ef449 854 git status --untracked-files=no >actual &&
1108cea7 855 test_cmp expected actual
db4ef449
MM
856'
857
858test_expect_success 'status while reverting commit (conflicts resolved)' '
859 echo reverted >to-revert.txt &&
860 git add to-revert.txt &&
59c22205 861 cat >expected <<EOF &&
1e2ae142 862On branch main
1c7969c9
MM
863You are currently reverting commit $TO_REVERT.
864 (all conflicts fixed: run "git revert --continue")
86ae43da 865 (use "git revert --skip" to skip this patch)
1c7969c9
MM
866 (use "git revert --abort" to cancel the revert operation)
867
868Changes to be committed:
80f537f7 869 (use "git restore --staged <file>..." to unstage)
1c7969c9
MM
870 modified: to-revert.txt
871
872Untracked files not listed (use -u option to show untracked files)
873EOF
db4ef449 874 git status --untracked-files=no >actual &&
1108cea7 875 test_cmp expected actual
db4ef449
MM
876'
877
878test_expect_success 'status after reverting commit' '
879 git revert --continue &&
59c22205 880 cat >expected <<\EOF &&
1e2ae142 881On branch main
1c7969c9 882nothing to commit (use -u to show untracked files)
4a72486d
PW
883EOF
884 git status --untracked-files=no >actual &&
1108cea7 885 test_cmp expected actual
4a72486d
PW
886'
887
888test_expect_success 'status while reverting after committing conflict resolution' '
889 test_when_finished "git revert --abort" &&
890 git reset --hard new &&
891 test_must_fail git revert old new &&
892 echo reverted >to-revert.txt &&
893 git commit -a &&
894 cat >expected <<EOF &&
1e2ae142 895On branch main
4a72486d
PW
896Revert currently in progress.
897 (run "git revert --continue" to continue)
86ae43da 898 (use "git revert --skip" to skip this patch)
4a72486d
PW
899 (use "git revert --abort" to cancel the revert operation)
900
901nothing to commit (use -u to show untracked files)
1c7969c9 902EOF
db4ef449 903 git status --untracked-files=no >actual &&
1108cea7 904 test_cmp expected actual
db4ef449
MM
905'
906
592e412d 907test_expect_success 'prepare for different number of commits rebased' '
1e2ae142 908 git reset --hard main &&
592e412d
GP
909 git checkout -b several_commits &&
910 test_commit one_commit main.txt one &&
911 test_commit two_commit main.txt two &&
912 test_commit three_commit main.txt three &&
913 test_commit four_commit main.txt four
914'
915
916test_expect_success 'status: one command done nothing remaining' '
917 FAKE_LINES="exec_exit_15" &&
918 export FAKE_LINES &&
919 test_when_finished "git rebase --abort" &&
920 ONTO=$(git rev-parse --short HEAD~3) &&
921 test_must_fail git rebase -i HEAD~3 &&
922 cat >expected <<EOF &&
923interactive rebase in progress; onto $ONTO
924Last command done (1 command done):
925 exec exit 15
926No commands remaining.
927You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
928 (use "git commit --amend" to amend the current commit)
929 (use "git rebase --continue" once you are satisfied with your changes)
930
931nothing to commit (use -u to show untracked files)
932EOF
933 git status --untracked-files=no >actual &&
1108cea7 934 test_cmp expected actual
592e412d
GP
935'
936
937test_expect_success 'status: two commands done with some white lines in done file' '
938 FAKE_LINES="1 > exec_exit_15 2 3" &&
939 export FAKE_LINES &&
940 test_when_finished "git rebase --abort" &&
941 ONTO=$(git rev-parse --short HEAD~3) &&
942 COMMIT4=$(git rev-parse --short HEAD) &&
943 COMMIT3=$(git rev-parse --short HEAD^) &&
944 COMMIT2=$(git rev-parse --short HEAD^^) &&
945 test_must_fail git rebase -i HEAD~3 &&
946 cat >expected <<EOF &&
947interactive rebase in progress; onto $ONTO
948Last commands done (2 commands done):
949 pick $COMMIT2 two_commit
950 exec exit 15
951Next commands to do (2 remaining commands):
952 pick $COMMIT3 three_commit
953 pick $COMMIT4 four_commit
954 (use "git rebase --edit-todo" to view and edit)
955You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
956 (use "git commit --amend" to amend the current commit)
957 (use "git rebase --continue" once you are satisfied with your changes)
958
959nothing to commit (use -u to show untracked files)
960EOF
961 git status --untracked-files=no >actual &&
1108cea7 962 test_cmp expected actual
592e412d
GP
963'
964
965test_expect_success 'status: two remaining commands with some white lines in todo file' '
966 FAKE_LINES="1 2 exec_exit_15 3 > 4" &&
967 export FAKE_LINES &&
968 test_when_finished "git rebase --abort" &&
969 ONTO=$(git rev-parse --short HEAD~4) &&
970 COMMIT4=$(git rev-parse --short HEAD) &&
971 COMMIT3=$(git rev-parse --short HEAD^) &&
972 COMMIT2=$(git rev-parse --short HEAD^^) &&
973 test_must_fail git rebase -i HEAD~4 &&
974 cat >expected <<EOF &&
975interactive rebase in progress; onto $ONTO
976Last commands done (3 commands done):
977 pick $COMMIT2 two_commit
978 exec exit 15
979 (see more in file .git/rebase-merge/done)
980Next commands to do (2 remaining commands):
981 pick $COMMIT3 three_commit
982 pick $COMMIT4 four_commit
983 (use "git rebase --edit-todo" to view and edit)
984You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
985 (use "git commit --amend" to amend the current commit)
986 (use "git rebase --continue" once you are satisfied with your changes)
987
988nothing to commit (use -u to show untracked files)
989EOF
990 git status --untracked-files=no >actual &&
1108cea7 991 test_cmp expected actual
592e412d
GP
992'
993
df9ded49
JS
994test_expect_success 'status: handle not-yet-started rebase -i gracefully' '
995 ONTO=$(git rev-parse --short HEAD^) &&
996 COMMIT=$(git rev-parse --short HEAD) &&
997 EDITOR="git status --untracked-files=no >actual" git rebase -i HEAD^ &&
998 cat >expected <<EOF &&
999On branch several_commits
1000No commands done.
1001Next command to do (1 remaining command):
1002 pick $COMMIT four_commit
1003 (use "git rebase --edit-todo" to view and edit)
1004You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
1005 (use "git commit --amend" to amend the current commit)
1006 (use "git rebase --continue" once you are satisfied with your changes)
1007
1008nothing to commit (use -u to show untracked files)
1009EOF
1108cea7 1010 test_cmp expected actual
df9ded49
JS
1011'
1012
70819263 1013test_done