Merge branch 'ak/git-strip-extension-from-dashed-command'
[git/gitweb.git] / t / t4055-diff-context.sh
blob741e0803c1ac0a418c98c7eee9cb449a7c60da06
1 #!/bin/sh
3 # Copyright (c) 2012 Mozilla Foundation
6 test_description='diff.context configuration'
8 . ./test-lib.sh
10 test_expect_success 'setup' '
11 cat >template <<-\EOF &&
12 firstline
18 preline
19 TARGET
20 postline
27 EOF
28 sed "/TARGET/d" >x <template &&
29 git update-index --add x &&
30 git commit -m initial &&
32 sed "s/TARGET/ADDED/" >x <template &&
33 git update-index --add x &&
34 git commit -m next &&
36 sed "s/TARGET/MODIFIED/" >x <template
39 test_expect_success 'the default number of context lines is 3' '
40 git diff >output &&
41 ! grep "^ d" output &&
42 grep "^ e" output &&
43 grep "^ j" output &&
44 ! grep "^ k" output
47 test_expect_success 'diff.context honored by "log"' '
48 git log -1 -p >output &&
49 ! grep firstline output &&
50 git config diff.context 8 &&
51 git log -1 -p >output &&
52 grep "^ firstline" output
55 test_expect_success 'The -U option overrides diff.context' '
56 git config diff.context 8 &&
57 git log -U4 -1 >output &&
58 ! grep "^ firstline" output
61 test_expect_success 'diff.context honored by "diff"' '
62 git config diff.context 8 &&
63 git diff >output &&
64 grep "^ firstline" output
67 test_expect_success 'plumbing not affected' '
68 git config diff.context 8 &&
69 git diff-files -p >output &&
70 ! grep "^ firstline" output
73 test_expect_success 'non-integer config parsing' '
74 git config diff.context no &&
75 test_must_fail git diff 2>output &&
76 test_i18ngrep "bad numeric config value" output
79 test_expect_success 'negative integer config parsing' '
80 git config diff.context -1 &&
81 test_must_fail git diff 2>output &&
82 test_i18ngrep "bad config variable" output
85 test_expect_success '-U0 is valid, so is diff.context=0' '
86 git config diff.context 0 &&
87 git diff >output &&
88 grep "^-ADDED" output &&
89 grep "^+MODIFIED" output
92 test_done