2006-08-15 08:24:55 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
2007-07-03 07:52:14 +02:00
|
|
|
test_description='git apply in reverse
|
2006-08-15 08:24:55 +02:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2021-10-31 00:24:18 +02:00
|
|
|
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2006-08-15 08:24:55 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
2021-12-09 06:11:05 +01:00
|
|
|
test_write_lines a b c d e f g h i j k l m n >file1 &&
|
2013-10-29 02:23:03 +01:00
|
|
|
perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
|
2006-08-15 08:24:55 +02:00
|
|
|
|
|
|
|
git add file1 file2 &&
|
|
|
|
git commit -m initial &&
|
|
|
|
git tag initial &&
|
|
|
|
|
2021-12-09 06:11:05 +01:00
|
|
|
test_write_lines a b c g h i J K L m o n p q >file1 &&
|
2013-10-29 02:23:03 +01:00
|
|
|
perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
|
2006-08-15 08:24:55 +02:00
|
|
|
|
|
|
|
git commit -a -m second &&
|
2006-08-17 01:09:25 +02:00
|
|
|
git tag second &&
|
2006-08-15 08:24:55 +02:00
|
|
|
|
2006-08-17 01:09:25 +02:00
|
|
|
git diff --binary initial second >patch
|
2006-08-15 08:24:55 +02:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply in forward' '
|
|
|
|
|
2014-04-30 18:23:04 +02:00
|
|
|
T0=$(git rev-parse "second^{tree}") &&
|
2006-08-17 01:09:25 +02:00
|
|
|
git reset --hard initial &&
|
2006-08-15 08:24:55 +02:00
|
|
|
git apply --index --binary patch &&
|
2014-04-30 18:23:04 +02:00
|
|
|
T1=$(git write-tree) &&
|
2006-08-17 01:09:25 +02:00
|
|
|
test "$T0" = "$T1"
|
2006-08-15 08:24:55 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply in reverse' '
|
|
|
|
|
2006-08-17 01:09:25 +02:00
|
|
|
git reset --hard second &&
|
2006-08-15 08:24:55 +02:00
|
|
|
git apply --reverse --binary --index patch &&
|
|
|
|
git diff >diff &&
|
2018-08-19 23:57:24 +02:00
|
|
|
test_must_be_empty diff
|
2006-08-15 08:24:55 +02:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2006-08-17 01:09:25 +02:00
|
|
|
test_expect_success 'setup separate repository lacking postimage' '
|
|
|
|
|
2013-11-10 16:47:29 +01:00
|
|
|
git archive --format=tar --prefix=initial/ initial | $TAR xf - &&
|
2006-08-17 01:09:25 +02:00
|
|
|
(
|
2007-01-12 22:01:46 +01:00
|
|
|
cd initial && git init && git add .
|
2006-08-17 01:09:25 +02:00
|
|
|
) &&
|
|
|
|
|
2013-11-10 16:47:29 +01:00
|
|
|
git archive --format=tar --prefix=second/ second | $TAR xf - &&
|
2006-08-17 01:09:25 +02:00
|
|
|
(
|
2007-01-12 22:01:46 +01:00
|
|
|
cd second && git init && git add .
|
2006-08-17 01:09:25 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply in forward without postimage' '
|
|
|
|
|
2014-04-30 18:23:04 +02:00
|
|
|
T0=$(git rev-parse "second^{tree}") &&
|
2006-08-17 01:09:25 +02:00
|
|
|
(
|
|
|
|
cd initial &&
|
|
|
|
git apply --index --binary ../patch &&
|
2014-04-30 18:23:04 +02:00
|
|
|
T1=$(git write-tree) &&
|
2006-08-17 01:09:25 +02:00
|
|
|
test "$T0" = "$T1"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply in reverse without postimage' '
|
|
|
|
|
2014-04-30 18:23:04 +02:00
|
|
|
T0=$(git rev-parse "initial^{tree}") &&
|
2006-08-17 01:09:25 +02:00
|
|
|
(
|
|
|
|
cd second &&
|
|
|
|
git apply --index --binary --reverse ../patch &&
|
2014-04-30 18:23:04 +02:00
|
|
|
T1=$(git write-tree) &&
|
2006-08-17 01:09:25 +02:00
|
|
|
test "$T0" = "$T1"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2007-07-07 19:50:39 +02:00
|
|
|
test_expect_success 'reversing a whitespace introduction' '
|
|
|
|
sed "s/a/a /" < file1 > file1.new &&
|
|
|
|
mv file1.new file1 &&
|
|
|
|
git diff | git apply --reverse --whitespace=error
|
|
|
|
'
|
|
|
|
|
2006-08-15 08:24:55 +02:00
|
|
|
test_done
|