blob: a9f4ddda6c3bd650634219968ecec92e5247cff7 [file] [log] [blame]
Junio C Hamano6a0ebe82006-08-14 23:24:55 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git apply in reverse
Junio C Hamano6a0ebe82006-08-14 23:24:55 -07007
8'
9
Ævar Arnfjörð Bjarmasonf54f48f2021-10-31 00:24:18 +020010
11TEST_PASSES_SANITIZE_LEAK=true
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070012. ./test-lib.sh
13
14test_expect_success setup '
15
Eric Sunshine08495412021-12-09 00:11:05 -050016 test_write_lines a b c d e f g h i j k l m n >file1 &&
Jeff King94221d22013-10-28 21:23:03 -040017 perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070018
19 git add file1 file2 &&
20 git commit -m initial &&
21 git tag initial &&
22
Eric Sunshine08495412021-12-09 00:11:05 -050023 test_write_lines a b c g h i J K L m o n p q >file1 &&
Jeff King94221d22013-10-28 21:23:03 -040024 perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070025
26 git commit -a -m second &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070027 git tag second &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070028
Junio C Hamano2cda1a22006-08-16 16:09:25 -070029 git diff --binary initial second >patch
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070030
31'
32
33test_expect_success 'apply in forward' '
34
Elia Pinto991a9c32014-04-30 09:23:04 -070035 T0=$(git rev-parse "second^{tree}") &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070036 git reset --hard initial &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070037 git apply --index --binary patch &&
Elia Pinto991a9c32014-04-30 09:23:04 -070038 T1=$(git write-tree) &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070039 test "$T0" = "$T1"
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070040'
41
42test_expect_success 'apply in reverse' '
43
Junio C Hamano2cda1a22006-08-16 16:09:25 -070044 git reset --hard second &&
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070045 git apply --reverse --binary --index patch &&
46 git diff >diff &&
SZEDER Gáborec21ac82018-08-19 23:57:24 +020047 test_must_be_empty diff
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070048
49'
50
Junio C Hamano2cda1a22006-08-16 16:09:25 -070051test_expect_success 'setup separate repository lacking postimage' '
52
John Keeping925cecc2013-11-10 15:47:29 +000053 git archive --format=tar --prefix=initial/ initial | $TAR xf - &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070054 (
Nicolas Pitre5c94f872007-01-12 16:01:46 -050055 cd initial && git init && git add .
Junio C Hamano2cda1a22006-08-16 16:09:25 -070056 ) &&
57
John Keeping925cecc2013-11-10 15:47:29 +000058 git archive --format=tar --prefix=second/ second | $TAR xf - &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070059 (
Nicolas Pitre5c94f872007-01-12 16:01:46 -050060 cd second && git init && git add .
Junio C Hamano2cda1a22006-08-16 16:09:25 -070061 )
62
63'
64
65test_expect_success 'apply in forward without postimage' '
66
Elia Pinto991a9c32014-04-30 09:23:04 -070067 T0=$(git rev-parse "second^{tree}") &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070068 (
69 cd initial &&
70 git apply --index --binary ../patch &&
Elia Pinto991a9c32014-04-30 09:23:04 -070071 T1=$(git write-tree) &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070072 test "$T0" = "$T1"
73 )
74'
75
76test_expect_success 'apply in reverse without postimage' '
77
Elia Pinto991a9c32014-04-30 09:23:04 -070078 T0=$(git rev-parse "initial^{tree}") &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070079 (
80 cd second &&
81 git apply --index --binary --reverse ../patch &&
Elia Pinto991a9c32014-04-30 09:23:04 -070082 T1=$(git write-tree) &&
Junio C Hamano2cda1a22006-08-16 16:09:25 -070083 test "$T0" = "$T1"
84 )
85'
86
Johannes Schindelin5fda48d2007-07-07 18:50:39 +010087test_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
Junio C Hamano6a0ebe82006-08-14 23:24:55 -070093test_done