Sync with 2.38.4
[git.git] / t / t4055-diff-context.sh
blob73048d0a52683bed2d56de3b0be77680cecaaf5a
1 #!/bin/sh
3 # Copyright (c) 2012 Mozilla Foundation
6 test_description='diff.context configuration'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 cat >template <<-\EOF &&
13 firstline
19 preline
20 TARGET
21 postline
28 EOF
29 sed "/TARGET/d" >x <template &&
30 git update-index --add x &&
31 git commit -m initial &&
33 sed "s/TARGET/ADDED/" >x <template &&
34 git update-index --add x &&
35 git commit -m next &&
37 sed "s/TARGET/MODIFIED/" >x <template
40 test_expect_success 'the default number of context lines is 3' '
41 git diff >output &&
42 ! grep "^ d" output &&
43 grep "^ e" output &&
44 grep "^ j" output &&
45 ! grep "^ k" output
48 test_expect_success 'diff.context honored by "log"' '
49 git log -1 -p >output &&
50 ! grep firstline output &&
51 git config diff.context 8 &&
52 git log -1 -p >output &&
53 grep "^ firstline" output
56 test_expect_success 'The -U option overrides diff.context' '
57 git config diff.context 8 &&
58 git log -U4 -1 >output &&
59 ! grep "^ firstline" output
62 test_expect_success 'diff.context honored by "diff"' '
63 git config diff.context 8 &&
64 git diff >output &&
65 grep "^ firstline" output
68 test_expect_success 'plumbing not affected' '
69 git config diff.context 8 &&
70 git diff-files -p >output &&
71 ! grep "^ firstline" output
74 test_expect_success 'non-integer config parsing' '
75 git config diff.context no &&
76 test_must_fail git diff 2>output &&
77 test_i18ngrep "bad numeric config value" output
80 test_expect_success 'negative integer config parsing' '
81 git config diff.context -1 &&
82 test_must_fail git diff 2>output &&
83 test_i18ngrep "bad config variable" output
86 test_expect_success '-U0 is valid, so is diff.context=0' '
87 git config diff.context 0 &&
88 git diff >output &&
89 grep "^-ADDED" output &&
90 grep "^+MODIFIED" output
93 test_done