]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4055-diff-context.sh
Merge branch 'mk/doc-gitfile-more' into maint-2.43
[thirdparty/git.git] / t / t4055-diff-context.sh
CommitLineData
6468a4e5
JM
1#!/bin/sh
2#
3# Copyright (c) 2012 Mozilla Foundation
4#
5
6test_description='diff.context configuration'
7
a52f07af 8TEST_PASSES_SANITIZE_LEAK=true
6468a4e5
JM
9. ./test-lib.sh
10
11test_expect_success 'setup' '
50fb51e7 12 cat >template <<-\EOF &&
6468a4e5
JM
13 firstline
14 b
15 c
16 d
17 e
18 f
19 preline
50fb51e7 20 TARGET
6468a4e5
JM
21 postline
22 i
23 j
24 k
25 l
26 m
27 n
28 EOF
50fb51e7 29 sed "/TARGET/d" >x <template &&
6468a4e5
JM
30 git update-index --add x &&
31 git commit -m initial &&
32
50fb51e7 33 sed "s/TARGET/ADDED/" >x <template &&
6468a4e5
JM
34 git update-index --add x &&
35 git commit -m next &&
36
50fb51e7 37 sed "s/TARGET/MODIFIED/" >x <template
6468a4e5
JM
38'
39
40test_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
46'
47
48test_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
54'
55
56test_expect_success 'The -U option overrides diff.context' '
57 git config diff.context 8 &&
58 git log -U4 -1 >output &&
59 ! grep "^ firstline" output
60'
61
62test_expect_success 'diff.context honored by "diff"' '
63 git config diff.context 8 &&
64 git diff >output &&
65 grep "^ firstline" output
66'
67
68test_expect_success 'plumbing not affected' '
69 git config diff.context 8 &&
70 git diff-files -p >output &&
71 ! grep "^ firstline" output
72'
73
74test_expect_success 'non-integer config parsing' '
75 git config diff.context no &&
76 test_must_fail git diff 2>output &&
6789275d 77 test_grep "bad numeric config value" output
6468a4e5
JM
78'
79
80test_expect_success 'negative integer config parsing' '
81 git config diff.context -1 &&
82 test_must_fail git diff 2>output &&
6789275d 83 test_grep "bad config variable" output
6468a4e5
JM
84'
85
86test_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
91'
92
93test_done