@@ -23,6 +23,17 @@ diff_cmp () {
23
23
test_cmp " $1 .filtered" " $2 .filtered"
24
24
}
25
25
26
+ # This function uses a trick to manipulate the interactive add to use color:
27
+ # the `want_color()` function special-cases the situation where a pager was
28
+ # spawned and Git now wants to output colored text: to detect that situation,
29
+ # the environment variable `GIT_PAGER_IN_USE` is set. However, color is
30
+ # suppressed despite that environment variable if the `TERM` variable
31
+ # indicates a dumb terminal, so we set that variable, too.
32
+
33
+ force_color () {
34
+ env GIT_PAGER_IN_USE=true TERM=vt100 " $@ "
35
+ }
36
+
26
37
test_expect_success ' setup (initial)' '
27
38
echo content >file &&
28
39
git add file &&
@@ -94,7 +105,6 @@ test_expect_success 'revert works (commit)' '
94
105
grep "unchanged *+3/-0 file" output
95
106
'
96
107
97
-
98
108
test_expect_success ' setup expected' '
99
109
cat >expected <<-\EOF
100
110
EOF
@@ -263,6 +273,35 @@ test_expect_success FILEMODE 'stage mode and hunk' '
263
273
264
274
# end of tests disabled when filemode is not usable
265
275
276
+ test_expect_success ' different prompts for mode change/deleted' '
277
+ git reset --hard &&
278
+ >file &&
279
+ >deleted &&
280
+ git add --chmod=+x file deleted &&
281
+ echo changed >file &&
282
+ rm deleted &&
283
+ test_write_lines n n n |
284
+ git -c core.filemode=true add -p >actual &&
285
+ sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
286
+ cat >expect <<-\EOF &&
287
+ (1/1) Stage deletion [y,n,q,a,d,?]?
288
+ (1/2) Stage mode change [y,n,q,a,d,j,J,g,/,?]?
289
+ (2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]?
290
+ EOF
291
+ test_cmp expect actual.filtered
292
+ '
293
+
294
+ test_expect_success ' correct message when there is nothing to do' '
295
+ git reset --hard &&
296
+ git add -p 2>err &&
297
+ test_i18ngrep "No changes" err &&
298
+ printf "\\0123" >binary &&
299
+ git add binary &&
300
+ printf "\\0abc" >binary &&
301
+ git add -p 2>err &&
302
+ test_i18ngrep "Only binary files changed" err
303
+ '
304
+
266
305
test_expect_success ' setup again' '
267
306
git reset --hard &&
268
307
test_chmod +x file &&
@@ -403,6 +442,28 @@ test_expect_failure 'split hunk "add -p (no, yes, edit)"' '
403
442
! grep "^+31" actual
404
443
'
405
444
445
+ test_expect_failure ' edit, adding lines to the first hunk' '
446
+ test_write_lines 10 11 20 30 40 50 51 60 >test &&
447
+ git reset &&
448
+ tr _ " " >patch <<-EOF &&
449
+ @@ -1,5 +1,6 @@
450
+ _10
451
+ +11
452
+ +12
453
+ _20
454
+ +21
455
+ +22
456
+ _30
457
+ EOF
458
+ # test sequence is s(plit), e(dit), n(o)
459
+ # q n q q is there to make sure we exit at the end.
460
+ printf "%s\n" s e n q n q q |
461
+ EDITOR=./fake_editor.sh git add -p 2>error &&
462
+ test_must_be_empty error &&
463
+ git diff --cached >actual &&
464
+ grep "^+22" actual
465
+ '
466
+
406
467
test_expect_success ' patch mode ignores unmerged entries' '
407
468
git reset --hard &&
408
469
test_commit conflict &&
@@ -429,35 +490,48 @@ test_expect_success 'patch mode ignores unmerged entries' '
429
490
diff_cmp expected diff
430
491
'
431
492
432
- test_expect_success TTY ' diffs can be colorized' '
493
+ test_expect_success ' diffs can be colorized' '
433
494
git reset --hard &&
434
495
435
496
echo content >test &&
436
- printf y | test_terminal git add -p >output 2>&1 &&
497
+ printf y >y &&
498
+ force_color git add -p >output 2>&1 <y &&
437
499
438
500
# We do not want to depend on the exact coloring scheme
439
501
# git uses for diffs, so just check that we saw some kind of color.
440
502
grep "$(printf "\\033")" output
441
503
'
442
504
443
- test_expect_success TTY ' diffFilter filters diff' '
505
+ test_expect_success ' diffFilter filters diff' '
444
506
git reset --hard &&
445
507
446
508
echo content >test &&
447
509
test_config interactive.diffFilter "sed s/^/foo:/" &&
448
- printf y | test_terminal git add -p >output 2>&1 &&
510
+ printf y >y &&
511
+ force_color git add -p >output 2>&1 <y &&
449
512
450
513
# avoid depending on the exact coloring or content of the prompts,
451
514
# and just make sure we saw our diff prefixed
452
515
grep foo:.*content output
453
516
'
454
517
455
- test_expect_success TTY ' detect bogus diffFilter output' '
518
+ test_expect_success ' detect bogus diffFilter output' '
456
519
git reset --hard &&
457
520
458
521
echo content >test &&
459
522
test_config interactive.diffFilter "echo too-short" &&
460
- printf y | test_must_fail test_terminal git add -p
523
+ printf y >y &&
524
+ test_must_fail force_color git add -p <y
525
+ '
526
+
527
+ test_expect_success ' diff.algorithm is passed to `git diff-files`' '
528
+ git reset --hard &&
529
+
530
+ >file &&
531
+ git add file &&
532
+ echo changed >file &&
533
+ test_must_fail git -c diff.algorithm=bogus add -p 2>err &&
534
+ test_i18ngrep "error: option diff-algorithm accepts " err
461
535
'
462
536
463
537
test_expect_success ' patch-mode via -i prompts for files' '
@@ -667,7 +741,7 @@ test_expect_success 'show help from add--helper' '
667
741
<BOLD;BLUE>What now<RESET>>$SP
668
742
Bye.
669
743
EOF
670
- test_write_lines h | GIT_PAGER_IN_USE=true TERM=vt100 git add -i >actual.colored &&
744
+ test_write_lines h | force_color git add -i >actual.colored &&
671
745
test_decode_color <actual.colored >actual &&
672
746
test_i18ncmp expect actual
673
747
'
0 commit comments