2006-08-15 10:24:55 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
2007-07-03 09:52:14 +04:00
|
|
|
test_description='git apply in reverse
|
2006-08-15 10:24:55 +04:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
for i in a b c d e f g h i j k l m n; do echo $i; done >file1 &&
|
|
|
|
tr "[ijk]" '\''[\0\1\2]'\'' <file1 >file2 &&
|
|
|
|
|
|
|
|
git add file1 file2 &&
|
|
|
|
git commit -m initial &&
|
|
|
|
git tag initial &&
|
|
|
|
|
|
|
|
for i in a b c g h i J K L m o n p q; do echo $i; done >file1 &&
|
|
|
|
tr "[mon]" '\''[\0\1\2]'\'' <file1 >file2 &&
|
|
|
|
|
|
|
|
git commit -a -m second &&
|
2006-08-17 03:09:25 +04:00
|
|
|
git tag second &&
|
2006-08-15 10:24:55 +04:00
|
|
|
|
2006-08-17 03:09:25 +04:00
|
|
|
git diff --binary initial second >patch
|
2006-08-15 10:24:55 +04:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply in forward' '
|
|
|
|
|
2006-08-17 03:09:25 +04:00
|
|
|
T0=`git rev-parse "second^{tree}"` &&
|
|
|
|
git reset --hard initial &&
|
2006-08-15 10:24:55 +04:00
|
|
|
git apply --index --binary patch &&
|
2006-08-17 03:09:25 +04:00
|
|
|
T1=`git write-tree` &&
|
|
|
|
test "$T0" = "$T1"
|
2006-08-15 10:24:55 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply in reverse' '
|
|
|
|
|
2006-08-17 03:09:25 +04:00
|
|
|
git reset --hard second &&
|
2006-08-15 10:24:55 +04:00
|
|
|
git apply --reverse --binary --index patch &&
|
|
|
|
git diff >diff &&
|
2007-02-26 01:36:53 +03:00
|
|
|
git diff /dev/null diff
|
2006-08-15 10:24:55 +04:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2006-08-17 03:09:25 +04:00
|
|
|
test_expect_success 'setup separate repository lacking postimage' '
|
|
|
|
|
|
|
|
git tar-tree initial initial | tar xf - &&
|
|
|
|
(
|
2007-01-13 00:01:46 +03:00
|
|
|
cd initial && git init && git add .
|
2006-08-17 03:09:25 +04:00
|
|
|
) &&
|
|
|
|
|
|
|
|
git tar-tree second second | tar xf - &&
|
|
|
|
(
|
2007-01-13 00:01:46 +03:00
|
|
|
cd second && git init && git add .
|
2006-08-17 03:09:25 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply in forward without postimage' '
|
|
|
|
|
|
|
|
T0=`git rev-parse "second^{tree}"` &&
|
|
|
|
(
|
|
|
|
cd initial &&
|
|
|
|
git apply --index --binary ../patch &&
|
|
|
|
T1=`git write-tree` &&
|
|
|
|
test "$T0" = "$T1"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply in reverse without postimage' '
|
|
|
|
|
|
|
|
T0=`git rev-parse "initial^{tree}"` &&
|
|
|
|
(
|
|
|
|
cd second &&
|
|
|
|
git apply --index --binary --reverse ../patch &&
|
|
|
|
T1=`git write-tree` &&
|
|
|
|
test "$T0" = "$T1"
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2007-07-07 21:50:39 +04: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 10:24:55 +04:00
|
|
|
test_done
|