Git fork
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='git apply in reverse
7
8'
9
10
11. ./test-lib.sh
12
13test_expect_success setup '
14
15 test_write_lines a b c d e f g h i j k l m n >file1 &&
16 tr "ijk" "\000\001\002" <file1 >file2 &&
17
18 git add file1 file2 &&
19 git commit -m initial &&
20 git tag initial &&
21
22 test_write_lines a b c g h i J K L m o n p q >file1 &&
23 tr "mon" "\000\001\002" <file1 >file2 &&
24
25 git commit -a -m second &&
26 git tag second &&
27
28 git diff --binary initial second >patch
29
30'
31
32test_expect_success 'apply in forward' '
33
34 T0=$(git rev-parse "second^{tree}") &&
35 git reset --hard initial &&
36 git apply --index --binary patch &&
37 T1=$(git write-tree) &&
38 test "$T0" = "$T1"
39'
40
41test_expect_success 'apply in reverse' '
42
43 git reset --hard second &&
44 git apply --reverse --binary --index patch &&
45 git diff >diff &&
46 test_must_be_empty diff
47
48'
49
50test_expect_success 'setup separate repository lacking postimage' '
51
52 git archive --format=tar --prefix=initial/ initial | $TAR xf - &&
53 (
54 cd initial && git init && git add .
55 ) &&
56
57 git archive --format=tar --prefix=second/ second | $TAR xf - &&
58 (
59 cd second && git init && git add .
60 )
61
62'
63
64test_expect_success 'apply in forward without postimage' '
65
66 T0=$(git rev-parse "second^{tree}") &&
67 (
68 cd initial &&
69 git apply --index --binary ../patch &&
70 T1=$(git write-tree) &&
71 test "$T0" = "$T1"
72 )
73'
74
75test_expect_success 'apply in reverse without postimage' '
76
77 T0=$(git rev-parse "initial^{tree}") &&
78 (
79 cd second &&
80 git apply --index --binary --reverse ../patch &&
81 T1=$(git write-tree) &&
82 test "$T0" = "$T1"
83 )
84'
85
86test_expect_success 'reversing a whitespace introduction' '
87 sed "s/a/a /" < file1 > file1.new &&
88 mv file1.new file1 &&
89 git diff | git apply --reverse --whitespace=error
90'
91
92test_done