blob: fca815392e305da095486888a38b6bff41e3d750 [file] [log] [blame]
Junio C Hamano6a0ebe82006-08-14 23:24:55 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git apply in reverse
Junio C Hamano6a0ebe82006-08-14 23:24:55 -07007
8'
9
10. ./test-lib.sh
11
12test_expect_success setup '
13
14 for i in a b c d e f g h i j k l m n; do echo $i; done >file1 &&
Junio C Hamano7096b642012-06-12 09:49:59 -070015 "$PERL_PATH" -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070016
17 git add file1 file2 &&
18 git commit -m initial &&
19 git tag initial &&
20
21 for i in a b c g h i J K L m o n p q; do echo $i; done >file1 &&
Junio C Hamano7096b642012-06-12 09:49:59 -070022 "$PERL_PATH" -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070023
24 git commit -a -m second &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070025 git tag second &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070026
Junio C Hamano2cda1a22006-08-16 16:09:25 -070027 git diff --binary initial second >patch
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070028
29'
30
31test_expect_success 'apply in forward' '
32
Junio C Hamano2cda1a22006-08-16 16:09:25 -070033 T0=`git rev-parse "second^{tree}"` &&
34 git reset --hard initial &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070035 git apply --index --binary patch &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070036 T1=`git write-tree` &&
37 test "$T0" = "$T1"
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070038'
39
40test_expect_success 'apply in reverse' '
41
Junio C Hamano2cda1a22006-08-16 16:09:25 -070042 git reset --hard second &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070043 git apply --reverse --binary --index patch &&
44 git diff >diff &&
Junio C Hamano3af82862008-05-23 22:28:56 -070045 test_cmp /dev/null diff
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070046
47'
48
Junio C Hamano2cda1a22006-08-16 16:09:25 -070049test_expect_success 'setup separate repository lacking postimage' '
50
Brandon Casey9a885fa2008-07-22 16:16:25 -050051 git tar-tree initial initial | $TAR xf - &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070052 (
Nicolas Pitre5c94f872007-01-12 16:01:46 -050053 cd initial && git init && git add .
Junio C Hamano2cda1a22006-08-16 16:09:25 -070054 ) &&
55
Brandon Casey9a885fa2008-07-22 16:16:25 -050056 git tar-tree second second | $TAR xf - &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070057 (
Nicolas Pitre5c94f872007-01-12 16:01:46 -050058 cd second && git init && git add .
Junio C Hamano2cda1a22006-08-16 16:09:25 -070059 )
60
61'
62
63test_expect_success 'apply in forward without postimage' '
64
65 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'
73
74test_expect_success 'apply in reverse without postimage' '
75
76 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'
84
Johannes Schindelin5fda48d2007-07-07 18:50:39 +010085test_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'
90
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070091test_done