t / t4032-diff-inter-hunk-context.shon commit Merge branch 'sg/worktree-remove-errormsg' (d4b12b9)
   1#!/bin/sh
   2
   3test_description='diff hunk fusing'
   4
   5. ./test-lib.sh
   6
   7f() {
   8        echo $1
   9        i=1
  10        while test $i -le $2
  11        do
  12                echo $i
  13                i=$(expr $i + 1)
  14        done
  15        echo $3
  16}
  17
  18t() {
  19        use_config=
  20        git config --unset diff.interHunkContext
  21
  22        case $# in
  23        4) hunks=$4; cmd="diff -U$3";;
  24        5) hunks=$5; cmd="diff -U$3 --inter-hunk-context=$4";;
  25        6) hunks=$5; cmd="diff -U$3"; git config diff.interHunkContext $4; use_config="(diff.interHunkContext=$4) ";;
  26        esac
  27        label="$use_config$cmd, $1 common $2"
  28        file=f$1
  29        expected=expected.$file.$3.$hunks
  30
  31        if ! test -f $file
  32        then
  33                f A $1 B >$file
  34                git add $file
  35                git commit -q -m. $file
  36                f X $1 Y >$file
  37        fi
  38
  39        test_expect_success "$label: count hunks ($hunks)" "
  40                test $(git $cmd $file | grep '^@@ ' | wc -l) = $hunks
  41        "
  42
  43        test -f $expected &&
  44        test_expect_success "$label: check output" "
  45                git $cmd $file | grep -v '^index ' >actual &&
  46                test_cmp $expected actual
  47        "
  48}
  49
  50cat <<EOF >expected.f1.0.1 || exit 1
  51diff --git a/f1 b/f1
  52--- a/f1
  53+++ b/f1
  54@@ -1,3 +1,3 @@
  55-A
  56+X
  57 1
  58-B
  59+Y
  60EOF
  61
  62cat <<EOF >expected.f1.0.2 || exit 1
  63diff --git a/f1 b/f1
  64--- a/f1
  65+++ b/f1
  66@@ -1 +1 @@
  67-A
  68+X
  69@@ -3 +3 @@ A
  70-B
  71+Y
  72EOF
  73
  74# common lines  ctx     intrctx hunks
  75t 1 line        0               2
  76t 1 line        0       0       2
  77t 1 line        0       1       1
  78t 1 line        0       2       1
  79t 1 line        1               1
  80
  81t 2 lines       0               2
  82t 2 lines       0       0       2
  83t 2 lines       0       1       2
  84t 2 lines       0       2       1
  85t 2 lines       1               1
  86
  87t 3 lines       1               2
  88t 3 lines       1       0       2
  89t 3 lines       1       1       1
  90t 3 lines       1       2       1
  91
  92t 9 lines       3               2
  93t 9 lines       3       2       2
  94t 9 lines       3       3       1
  95
  96#                                       use diff.interHunkContext?
  97t 1 line        0       0       2       config
  98t 1 line        0       1       1       config
  99t 1 line        0       2       1       config
 100t 9 lines       3       3       1       config
 101t 2 lines       0       0       2       config
 102t 2 lines       0       1       2       config
 103t 2 lines       0       2       1       config
 104t 3 lines       1       0       2       config
 105t 3 lines       1       1       1       config
 106t 3 lines       1       2       1       config
 107t 9 lines       3       2       2       config
 108t 9 lines       3       3       1       config
 109
 110test_expect_success 'diff.interHunkContext invalid' '
 111        git config diff.interHunkContext asdf &&
 112        test_must_fail git diff &&
 113        git config diff.interHunkContext -1 &&
 114        test_must_fail git diff
 115'
 116
 117test_done