3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git apply in reverse
11 TEST_PASSES_SANITIZE_LEAK
=true
14 test_expect_success setup
'
16 test_write_lines a b c d e f g h i j k l m n >file1 &&
17 perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
19 git add file1 file2 &&
20 git commit -m initial &&
23 test_write_lines a b c g h i J K L m o n p q >file1 &&
24 perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
26 git commit -a -m second &&
29 git diff --binary initial second >patch
33 test_expect_success
'apply in forward' '
35 T0=$(git rev-parse "second^{tree}") &&
36 git reset --hard initial &&
37 git apply --index --binary patch &&
38 T1=$(git write-tree) &&
42 test_expect_success
'apply in reverse' '
44 git reset --hard second &&
45 git apply --reverse --binary --index patch &&
47 test_must_be_empty diff
51 test_expect_success
'setup separate repository lacking postimage' '
53 git archive --format=tar --prefix=initial/ initial | $TAR xf - &&
55 cd initial && git init && git add .
58 git archive --format=tar --prefix=second/ second | $TAR xf - &&
60 cd second && git init && git add .
65 test_expect_success
'apply in forward without postimage' '
67 T0=$(git rev-parse "second^{tree}") &&
70 git apply --index --binary ../patch &&
71 T1=$(git write-tree) &&
76 test_expect_success
'apply in reverse without postimage' '
78 T0=$(git rev-parse "initial^{tree}") &&
81 git apply --index --binary --reverse ../patch &&
82 T1=$(git write-tree) &&
87 test_expect_success
'reversing a whitespace introduction' '
88 sed "s/a/a /" < file1 > file1.new &&
90 git diff | git apply --reverse --whitespace=error