t / t4125-apply-ws-fuzz.shon commit doc: promote "git restore" (80f537f)
   1#!/bin/sh
   2
   3test_description='applying patch that has broken whitespaces in context'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        >file &&
  10        git add file &&
  11
  12        # file-0 is full of whitespace breakages
  13        for l in a bb c d eeee f ggg h
  14        do
  15                echo "$l "
  16        done >file-0 &&
  17
  18        # patch-0 creates a whitespace broken file
  19        cat file-0 >file &&
  20        git diff >patch-0 &&
  21        git add file &&
  22
  23        # file-1 is still full of whitespace breakages,
  24        # but has one line updated, without fixing any
  25        # whitespaces.
  26        # patch-1 records that change.
  27        sed -e "s/d/D/" file-0 >file-1 &&
  28        cat file-1 >file &&
  29        git diff >patch-1 &&
  30
  31        # patch-all is the effect of both patch-0 and patch-1
  32        >file &&
  33        git add file &&
  34        cat file-1 >file &&
  35        git diff >patch-all &&
  36
  37        # patch-2 is the same as patch-1 but is based
  38        # on a version that already has whitespace fixed,
  39        # and does not introduce whitespace breakages.
  40        sed -e "s/ \$//" patch-1 >patch-2 &&
  41
  42        # If all whitespace breakages are fixed the contents
  43        # should look like file-fixed
  44        sed -e "s/ \$//" file-1 >file-fixed
  45
  46'
  47
  48test_expect_success nofix '
  49
  50        >file &&
  51        git add file &&
  52
  53        # Baseline.  Applying without fixing any whitespace
  54        # breakages.
  55        git apply --whitespace=nowarn patch-0 &&
  56        git apply --whitespace=nowarn patch-1 &&
  57
  58        # The result should obviously match.
  59        test_cmp file-1 file
  60'
  61
  62test_expect_success 'withfix (forward)' '
  63
  64        >file &&
  65        git add file &&
  66
  67        # The first application will munge the context lines
  68        # the second patch depends on.  We should be able to
  69        # adjust and still apply.
  70        git apply --whitespace=fix patch-0 &&
  71        git apply --whitespace=fix patch-1 &&
  72
  73        test_cmp file-fixed file
  74'
  75
  76test_expect_success 'withfix (backward)' '
  77
  78        >file &&
  79        git add file &&
  80
  81        # Now we have a whitespace breakages on our side.
  82        git apply --whitespace=nowarn patch-0 &&
  83
  84        # And somebody sends in a patch based on image
  85        # with whitespace already fixed.
  86        git apply --whitespace=fix patch-2 &&
  87
  88        # The result should accept the whitespace fixed
  89        # postimage.  But the line with "h" is beyond context
  90        # horizon and left unfixed.
  91
  92        sed -e /h/d file-fixed >fixed-head &&
  93        sed -e /h/d file >file-head &&
  94        test_cmp fixed-head file-head &&
  95
  96        sed -n -e /h/p file-fixed >fixed-tail &&
  97        sed -n -e /h/p file >file-tail &&
  98
  99        ! test_cmp fixed-tail file-tail
 100
 101'
 102
 103test_done