| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2012 Mozilla Foundation |
| 4 | # |
| 5 | |
| 6 | test_description='diff.context configuration' |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'setup' ' |
| 11 | cat >template <<-\EOF && |
| 12 | firstline |
| 13 | b |
| 14 | c |
| 15 | d |
| 16 | e |
| 17 | f |
| 18 | preline |
| 19 | TARGET |
| 20 | postline |
| 21 | i |
| 22 | j |
| 23 | k |
| 24 | l |
| 25 | m |
| 26 | n |
| 27 | EOF |
| 28 | sed "/TARGET/d" >x <template && |
| 29 | git update-index --add x && |
| 30 | git commit -m initial && |
| 31 | |
| 32 | sed "s/TARGET/ADDED/" >x <template && |
| 33 | git update-index --add x && |
| 34 | git commit -m next && |
| 35 | |
| 36 | sed "s/TARGET/MODIFIED/" >x <template |
| 37 | ' |
| 38 | |
| 39 | test_expect_success 'the default number of context lines is 3' ' |
| 40 | git diff >output && |
| 41 | test_grep ! "^ d" output && |
| 42 | test_grep "^ e" output && |
| 43 | test_grep "^ j" output && |
| 44 | test_grep ! "^ k" output |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'diff.context honored by "log"' ' |
| 48 | git log -1 -p >output && |
| 49 | test_grep ! firstline output && |
| 50 | test_config diff.context 8 && |
| 51 | git log -1 -p >output && |
| 52 | test_grep "^ firstline" output |
| 53 | ' |
| 54 | |
| 55 | test_expect_success 'The -U option overrides diff.context' ' |
| 56 | test_config diff.context 8 && |
| 57 | git log -U4 -1 >output && |
| 58 | test_grep ! "^ firstline" output |
| 59 | ' |
| 60 | |
| 61 | test_expect_success 'diff.context honored by "diff"' ' |
| 62 | test_config diff.context 8 && |
| 63 | git diff >output && |
| 64 | test_grep "^ firstline" output |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'plumbing not affected' ' |
| 68 | test_config diff.context 8 && |
| 69 | git diff-files -p >output && |
| 70 | test_grep ! "^ firstline" output |
| 71 | ' |
| 72 | |
| 73 | test_expect_success 'non-integer config parsing' ' |
| 74 | test_config diff.context no && |
| 75 | test_must_fail git diff 2>output && |
| 76 | test_grep "bad numeric config value" output |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'negative integer config parsing' ' |
| 80 | test_config diff.context -1 && |
| 81 | test_must_fail git diff 2>output && |
| 82 | test_grep "bad config variable" output |
| 83 | ' |
| 84 | |
| 85 | test_expect_success '-U-1 is rejected' ' |
| 86 | test_must_fail git diff -U-1 2>err && |
| 87 | test_grep "expects a non-negative integer" err |
| 88 | ' |
| 89 | |
| 90 | test_expect_success '-U0 is valid, so is diff.context=0' ' |
| 91 | test_config diff.context 0 && |
| 92 | git diff >output && |
| 93 | test_grep "^-ADDED" output && |
| 94 | test_grep "^+MODIFIED" output |
| 95 | ' |
| 96 | |
| 97 | test_expect_success '-U2147483647 works' ' |
| 98 | echo APPENDED >>x && |
| 99 | test_line_count = 16 x && |
| 100 | git diff -U2147483647 >output && |
| 101 | test_line_count = 22 output && |
| 102 | test_grep "^-ADDED" output && |
| 103 | test_grep "^+MODIFIED" output && |
| 104 | test_grep "^+APPENDED" output |
| 105 | ' |
| 106 | |
| 107 | test_done |