Merge branch 'cp/git-flush-is-an-env-bool'
[alt-git.git] / t / t4116-apply-reverse.sh
bloba9f4ddda6c3bd650634219968ecec92e5247cff7
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git apply in reverse
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
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 &&
21 git tag 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 &&
27 git tag 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) &&
39 test "$T0" = "$T1"
42 test_expect_success 'apply in reverse' '
44 git reset --hard second &&
45 git apply --reverse --binary --index patch &&
46 git diff >diff &&
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 .
56 ) &&
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}") &&
69 cd initial &&
70 git apply --index --binary ../patch &&
71 T1=$(git write-tree) &&
72 test "$T0" = "$T1"
76 test_expect_success 'apply in reverse without postimage' '
78 T0=$(git rev-parse "initial^{tree}") &&
80 cd second &&
81 git apply --index --binary --reverse ../patch &&
82 T1=$(git write-tree) &&
83 test "$T0" = "$T1"
87 test_expect_success 'reversing a whitespace introduction' '
88 sed "s/a/a /" < file1 > file1.new &&
89 mv file1.new file1 &&
90 git diff | git apply --reverse --whitespace=error
93 test_done