]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4116-apply-reverse.sh
The third batch
[thirdparty/git.git] / t / t4116-apply-reverse.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 test_description='git apply in reverse
7
8 '
9
10
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13
14 test_expect_success setup '
15
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 &&
18
19 git add file1 file2 &&
20 git commit -m initial &&
21 git tag initial &&
22
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 &&
25
26 git commit -a -m second &&
27 git tag second &&
28
29 git diff --binary initial second >patch
30
31 '
32
33 test_expect_success 'apply in forward' '
34
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"
40 '
41
42 test_expect_success 'apply in reverse' '
43
44 git reset --hard second &&
45 git apply --reverse --binary --index patch &&
46 git diff >diff &&
47 test_must_be_empty diff
48
49 '
50
51 test_expect_success 'setup separate repository lacking postimage' '
52
53 git archive --format=tar --prefix=initial/ initial | $TAR xf - &&
54 (
55 cd initial && git init && git add .
56 ) &&
57
58 git archive --format=tar --prefix=second/ second | $TAR xf - &&
59 (
60 cd second && git init && git add .
61 )
62
63 '
64
65 test_expect_success 'apply in forward without postimage' '
66
67 T0=$(git rev-parse "second^{tree}") &&
68 (
69 cd initial &&
70 git apply --index --binary ../patch &&
71 T1=$(git write-tree) &&
72 test "$T0" = "$T1"
73 )
74 '
75
76 test_expect_success 'apply in reverse without postimage' '
77
78 T0=$(git rev-parse "initial^{tree}") &&
79 (
80 cd second &&
81 git apply --index --binary --reverse ../patch &&
82 T1=$(git write-tree) &&
83 test "$T0" = "$T1"
84 )
85 '
86
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
91 '
92
93 test_done