Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 6 | test_description='git apply in reverse |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 7 | |
| 8 | ' |
| 9 | |
Ævar Arnfjörð Bjarmason | f54f48f | 2021-10-31 00:24:18 +0200 | [diff] [blame] | 10 | |
| 11 | TEST_PASSES_SANITIZE_LEAK=true |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 12 | . ./test-lib.sh |
| 13 | |
| 14 | test_expect_success setup ' |
| 15 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 16 | test_write_lines a b c d e f g h i j k l m n >file1 && |
Jeff King | 94221d2 | 2013-10-28 21:23:03 -0400 | [diff] [blame] | 17 | perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 && |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 18 | |
| 19 | git add file1 file2 && |
| 20 | git commit -m initial && |
| 21 | git tag initial && |
| 22 | |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 23 | test_write_lines a b c g h i J K L m o n p q >file1 && |
Jeff King | 94221d2 | 2013-10-28 21:23:03 -0400 | [diff] [blame] | 24 | perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 && |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 25 | |
| 26 | git commit -a -m second && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 27 | git tag second && |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 28 | |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 29 | git diff --binary initial second >patch |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 30 | |
| 31 | ' |
| 32 | |
| 33 | test_expect_success 'apply in forward' ' |
| 34 | |
Elia Pinto | 991a9c3 | 2014-04-30 09:23:04 -0700 | [diff] [blame] | 35 | T0=$(git rev-parse "second^{tree}") && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 36 | git reset --hard initial && |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 37 | git apply --index --binary patch && |
Elia Pinto | 991a9c3 | 2014-04-30 09:23:04 -0700 | [diff] [blame] | 38 | T1=$(git write-tree) && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 39 | test "$T0" = "$T1" |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 40 | ' |
| 41 | |
| 42 | test_expect_success 'apply in reverse' ' |
| 43 | |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 44 | git reset --hard second && |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 45 | git apply --reverse --binary --index patch && |
| 46 | git diff >diff && |
SZEDER Gábor | ec21ac8 | 2018-08-19 23:57:24 +0200 | [diff] [blame] | 47 | test_must_be_empty diff |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 48 | |
| 49 | ' |
| 50 | |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 51 | test_expect_success 'setup separate repository lacking postimage' ' |
| 52 | |
John Keeping | 925cecc | 2013-11-10 15:47:29 +0000 | [diff] [blame] | 53 | git archive --format=tar --prefix=initial/ initial | $TAR xf - && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 54 | ( |
Nicolas Pitre | 5c94f87 | 2007-01-12 16:01:46 -0500 | [diff] [blame] | 55 | cd initial && git init && git add . |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 56 | ) && |
| 57 | |
John Keeping | 925cecc | 2013-11-10 15:47:29 +0000 | [diff] [blame] | 58 | git archive --format=tar --prefix=second/ second | $TAR xf - && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 59 | ( |
Nicolas Pitre | 5c94f87 | 2007-01-12 16:01:46 -0500 | [diff] [blame] | 60 | cd second && git init && git add . |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 61 | ) |
| 62 | |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'apply in forward without postimage' ' |
| 66 | |
Elia Pinto | 991a9c3 | 2014-04-30 09:23:04 -0700 | [diff] [blame] | 67 | T0=$(git rev-parse "second^{tree}") && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 68 | ( |
| 69 | cd initial && |
| 70 | git apply --index --binary ../patch && |
Elia Pinto | 991a9c3 | 2014-04-30 09:23:04 -0700 | [diff] [blame] | 71 | T1=$(git write-tree) && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 72 | test "$T0" = "$T1" |
| 73 | ) |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'apply in reverse without postimage' ' |
| 77 | |
Elia Pinto | 991a9c3 | 2014-04-30 09:23:04 -0700 | [diff] [blame] | 78 | T0=$(git rev-parse "initial^{tree}") && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 79 | ( |
| 80 | cd second && |
| 81 | git apply --index --binary --reverse ../patch && |
Elia Pinto | 991a9c3 | 2014-04-30 09:23:04 -0700 | [diff] [blame] | 82 | T1=$(git write-tree) && |
Junio C Hamano | 2cda1a2 | 2006-08-16 16:09:25 -0700 | [diff] [blame] | 83 | test "$T0" = "$T1" |
| 84 | ) |
| 85 | ' |
| 86 | |
Johannes Schindelin | 5fda48d | 2007-07-07 18:50:39 +0100 | [diff] [blame] | 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 | |
Junio C Hamano | 6a0ebe8 | 2006-08-14 23:24:55 -0700 | [diff] [blame] | 93 | test_done |