1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5test_description='git apply in reverse
   7'
   9. ./test-lib.sh
  11test_expect_success setup '
  13        for i in a b c d e f g h i j k l m n; do echo $i; done >file1 &&
  15        "$PERL_PATH" -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
  16        git add file1 file2 &&
  18        git commit -m initial &&
  19        git tag initial &&
  20        for i in a b c g h i J K L m o n p q; do echo $i; done >file1 &&
  22        "$PERL_PATH" -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
  23        git commit -a -m second &&
  25        git tag second &&
  26        git diff --binary initial second >patch
  28'
  30test_expect_success 'apply in forward' '
  32        T0=`git rev-parse "second^{tree}"` &&
  34        git reset --hard initial &&
  35        git apply --index --binary patch &&
  36        T1=`git write-tree` &&
  37        test "$T0" = "$T1"
  38'
  39test_expect_success 'apply in reverse' '
  41        git reset --hard second &&
  43        git apply --reverse --binary --index patch &&
  44        git diff >diff &&
  45        test_cmp /dev/null diff
  46'
  48test_expect_success 'setup separate repository lacking postimage' '
  50        git tar-tree initial initial | $TAR xf - &&
  52        (
  53                cd initial && git init && git add .
  54        ) &&
  55        git tar-tree second second | $TAR xf - &&
  57        (
  58                cd second && git init && git add .
  59        )
  60'
  62test_expect_success 'apply in forward without postimage' '
  64        T0=`git rev-parse "second^{tree}"` &&
  66        (
  67                cd initial &&
  68                git apply --index --binary ../patch &&
  69                T1=`git write-tree` &&
  70                test "$T0" = "$T1"
  71        )
  72'
  73test_expect_success 'apply in reverse without postimage' '
  75        T0=`git rev-parse "initial^{tree}"` &&
  77        (
  78                cd second &&
  79                git apply --index --binary --reverse ../patch &&
  80                T1=`git write-tree` &&
  81                test "$T0" = "$T1"
  82        )
  83'
  84test_expect_success 'reversing a whitespace introduction' '
  86        sed "s/a/a /" < file1 > file1.new &&
  87        mv file1.new file1 &&
  88        git diff | git apply --reverse --whitespace=error
  89'
  90test_done