1#!/bin/sh
   2#
   3# Copyright (c) 2007 Junio C Hamano
   4#
   5test_description='git apply --whitespace=strip and configuration file.
   7'
   9. ./test-lib.sh
  11test_expect_success setup '
  13        mkdir sub &&
  14        echo A >sub/file1 &&
  15        cp sub/file1 saved &&
  16        git add sub/file1 &&
  17        echo "B " >sub/file1 &&
  18        git diff >patch.file
  19'
  20# Also handcraft GNU diff output; note this has trailing whitespace.
  22cat >gpatch.file <<\EOF &&
  23--- file1       2007-02-21 01:04:24.000000000 -0800
  24+++ file1+      2007-02-21 01:07:44.000000000 -0800
  25@@ -1 +1 @@
  26-A
  27+B 
  28EOF
  29sed -e 's|file1|sub/&|' gpatch.file >gpatch-sub.file &&
  31sed -e '
  32        /^--- /s|file1|a/sub/&|
  33        /^+++ /s|file1|b/sub/&|
  34' gpatch.file >gpatch-ab-sub.file &&
  35check_result () {
  37        if grep " " "$1"
  38        then
  39                echo "Eh?"
  40                false
  41        elif grep B "$1"
  42        then
  43                echo Happy
  44        else
  45                echo "Huh?"
  46                false
  47        fi
  48}
  49test_expect_success 'apply --whitespace=strip' '
  51        rm -f sub/file1 &&
  53        cp saved sub/file1 &&
  54        git update-index --refresh &&
  55        git apply --whitespace=strip patch.file &&
  57        check_result sub/file1
  58'
  59test_expect_success 'apply --whitespace=strip from config' '
  61        rm -f sub/file1 &&
  63        cp saved sub/file1 &&
  64        git update-index --refresh &&
  65        git config apply.whitespace strip &&
  67        git apply patch.file &&
  68        check_result sub/file1
  69'
  70D=`pwd`
  72test_expect_success 'apply --whitespace=strip in subdir' '
  74        cd "$D" &&
  76        git config --unset-all apply.whitespace
  77        rm -f sub/file1 &&
  78        cp saved sub/file1 &&
  79        git update-index --refresh &&
  80        cd sub &&
  82        git apply --whitespace=strip ../patch.file &&
  83        check_result file1
  84'
  85test_expect_success 'apply --whitespace=strip from config in subdir' '
  87        cd "$D" &&
  89        git config apply.whitespace strip &&
  90        rm -f sub/file1 &&
  91        cp saved sub/file1 &&
  92        git update-index --refresh &&
  93        cd sub &&
  95        git apply ../patch.file &&
  96        check_result file1
  97'
  98test_expect_success 'same in subdir but with traditional patch input' '
 100        cd "$D" &&
 102        git config apply.whitespace strip &&
 103        rm -f sub/file1 &&
 104        cp saved sub/file1 &&
 105        git update-index --refresh &&
 106        cd sub &&
 108        git apply ../gpatch.file &&
 109        check_result file1
 110'
 111test_expect_success 'same but with traditional patch input of depth 1' '
 113        cd "$D" &&
 115        git config apply.whitespace strip &&
 116        rm -f sub/file1 &&
 117        cp saved sub/file1 &&
 118        git update-index --refresh &&
 119        cd sub &&
 121        git apply ../gpatch-sub.file &&
 122        check_result file1
 123'
 124test_expect_success 'same but with traditional patch input of depth 2' '
 126        cd "$D" &&
 128        git config apply.whitespace strip &&
 129        rm -f sub/file1 &&
 130        cp saved sub/file1 &&
 131        git update-index --refresh &&
 132        cd sub &&
 134        git apply ../gpatch-ab-sub.file &&
 135        check_result file1
 136'
 137test_expect_success 'same but with traditional patch input of depth 1' '
 139        cd "$D" &&
 141        git config apply.whitespace strip &&
 142        rm -f sub/file1 &&
 143        cp saved sub/file1 &&
 144        git update-index --refresh &&
 145        git apply -p0 gpatch-sub.file &&
 147        check_result sub/file1
 148'
 149test_expect_success 'same but with traditional patch input of depth 2' '
 151        cd "$D" &&
 153        git config apply.whitespace strip &&
 154        rm -f sub/file1 &&
 155        cp saved sub/file1 &&
 156        git update-index --refresh &&
 157        git apply gpatch-ab-sub.file &&
 159        check_result sub/file1
 160'
 161test_done