]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4116-apply-reverse.sh
The third batch
[thirdparty/git.git] / t / t4116-apply-reverse.sh
CommitLineData
6a0ebe8c
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git apply in reverse
6a0ebe8c
JH
7
8'
9
f54f48fc
ÆAB
10
11TEST_PASSES_SANITIZE_LEAK=true
6a0ebe8c
JH
12. ./test-lib.sh
13
14test_expect_success setup '
15
08495412 16 test_write_lines a b c d e f g h i j k l m n >file1 &&
94221d22 17 perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
6a0ebe8c
JH
18
19 git add file1 file2 &&
20 git commit -m initial &&
21 git tag initial &&
22
08495412 23 test_write_lines a b c g h i J K L m o n p q >file1 &&
94221d22 24 perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
6a0ebe8c
JH
25
26 git commit -a -m second &&
2cda1a21 27 git tag second &&
6a0ebe8c 28
2cda1a21 29 git diff --binary initial second >patch
6a0ebe8c
JH
30
31'
32
33test_expect_success 'apply in forward' '
34
991a9c3a 35 T0=$(git rev-parse "second^{tree}") &&
2cda1a21 36 git reset --hard initial &&
6a0ebe8c 37 git apply --index --binary patch &&
991a9c3a 38 T1=$(git write-tree) &&
2cda1a21 39 test "$T0" = "$T1"
6a0ebe8c
JH
40'
41
42test_expect_success 'apply in reverse' '
43
2cda1a21 44 git reset --hard second &&
6a0ebe8c
JH
45 git apply --reverse --binary --index patch &&
46 git diff >diff &&
ec21ac8c 47 test_must_be_empty diff
6a0ebe8c
JH
48
49'
50
2cda1a21
JH
51test_expect_success 'setup separate repository lacking postimage' '
52
925ceccf 53 git archive --format=tar --prefix=initial/ initial | $TAR xf - &&
2cda1a21 54 (
5c94f87e 55 cd initial && git init && git add .
2cda1a21
JH
56 ) &&
57
925ceccf 58 git archive --format=tar --prefix=second/ second | $TAR xf - &&
2cda1a21 59 (
5c94f87e 60 cd second && git init && git add .
2cda1a21
JH
61 )
62
63'
64
65test_expect_success 'apply in forward without postimage' '
66
991a9c3a 67 T0=$(git rev-parse "second^{tree}") &&
2cda1a21
JH
68 (
69 cd initial &&
70 git apply --index --binary ../patch &&
991a9c3a 71 T1=$(git write-tree) &&
2cda1a21
JH
72 test "$T0" = "$T1"
73 )
74'
75
76test_expect_success 'apply in reverse without postimage' '
77
991a9c3a 78 T0=$(git rev-parse "initial^{tree}") &&
2cda1a21
JH
79 (
80 cd second &&
81 git apply --index --binary --reverse ../patch &&
991a9c3a 82 T1=$(git write-tree) &&
2cda1a21
JH
83 test "$T0" = "$T1"
84 )
85'
86
5fda48d6
JS
87test_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
6a0ebe8c 93test_done