From 2cda1a214e9d2e362242027b4b622ecb3d9260de Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 16 Aug 2006 16:09:25 -0700 Subject: apply --reverse: tie it all together. Add a few tests, usage string, and documentation. Signed-off-by: Junio C Hamano --- t/t4116-apply-reverse.sh | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 't') diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index 69aebe6005..74f5c2a575 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -22,25 +22,64 @@ test_expect_success setup ' tr "[mon]" '\''[\0\1\2]'\'' file2 && git commit -a -m second && + git tag second && - git diff --binary -R initial >patch + git diff --binary initial second >patch ' test_expect_success 'apply in forward' ' + T0=`git rev-parse "second^{tree}"` && + git reset --hard initial && git apply --index --binary patch && - git diff initial >diff && - diff -u /dev/null diff - + T1=`git write-tree` && + test "$T0" = "$T1" ' test_expect_success 'apply in reverse' ' + git reset --hard second && git apply --reverse --binary --index patch && git diff >diff && diff -u /dev/null diff ' +test_expect_success 'setup separate repository lacking postimage' ' + + git tar-tree initial initial | tar xf - && + ( + cd initial && git init-db && git add . + ) && + + git tar-tree second second | tar xf - && + ( + cd second && git init-db && git add . + ) + +' + +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" + ) +' + test_done -- cgit v1.2.1 From 57dc397cff09bfabd79ddbc38b704cdd0c2bc6e3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 16 Aug 2006 17:55:29 -0700 Subject: git-apply --reject With the new flag "--reject", hunks that do not apply are sent to the standard output, and the usable hunks are applied. The command itself exits with non-zero status when this happens, so that the user or wrapper can take notice and sort the remaining mess out. Signed-off-by: Junio C Hamano --- t/t4117-apply-reject.sh | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 t/t4117-apply-reject.sh (limited to 't') diff --git a/t/t4117-apply-reject.sh b/t/t4117-apply-reject.sh new file mode 100755 index 0000000000..3362819c3a --- /dev/null +++ b/t/t4117-apply-reject.sh @@ -0,0 +1,96 @@ +#!/bin/sh +# +# Copyright (c) 2005 Junio C Hamano +# + +test_description='git-apply with rejects + +' + +. ./test-lib.sh + +test_expect_success setup ' + for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 + do + echo $i + done >file1 && + cat file1 >saved.file1 && + git update-index --add file1 && + git commit -m initial && + + for i in 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 + do + echo $i + done >file1 && + git diff >patch.1 && + + mv file1 file2 && + git update-index --add --remove file1 file2 && + git diff -M HEAD >patch.2 && + + rm -f file1 file2 && + mv saved.file1 file1 && + git update-index --add --remove file1 file2 && + + for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 + do + echo $i + done >file1 && + + cat file1 >saved.file1 +' + +test_expect_success 'apply without --reject should fail' ' + + if git apply patch.1 + then + echo "Eh? Why?" + exit 1 + fi + + diff -u file1 saved.file1 +' + +test_expect_success 'apply with --reject should fail but update the file' ' + + cat saved.file1 >file1 + + if git apply --reject patch.1 >rejects + then + echo "succeeds with --reject?" + exit 1 + fi + cat rejects + for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 + do + echo $i + done >expected.file1 && + + diff -u file1 expected.file1 +' + +test_expect_success 'apply with --reject should fail but update the file' ' + + cat saved.file1 >file1 + + if git apply --reject patch.2 >rejects + then + echo "succeeds with --reject?" + exit 1 + fi + + cat rejects + + for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 + do + echo $i + done >expected.file2 && + + test -f file1 && { + echo "file1 still exists?" + exit 1 + } + diff -u file2 expected.file2 +' + +test_done -- cgit v1.2.1 From 82e2765f59126f96da6e5dc30adf7c6189e9697d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 18 Aug 2006 03:10:19 -0700 Subject: git-apply --reject: send rejects to .rej files. ... just like everybody else does, instead of sending it to the standard output, which was just silly. Signed-off-by: Junio C Hamano --- t/t4117-apply-reject.sh | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 't') diff --git a/t/t4117-apply-reject.sh b/t/t4117-apply-reject.sh index 3362819c3a..1cf9a2e7a7 100755 --- a/t/t4117-apply-reject.sh +++ b/t/t4117-apply-reject.sh @@ -23,6 +23,12 @@ test_expect_success setup ' echo $i done >file1 && git diff >patch.1 && + cat file1 >clean && + + for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 + do + echo $i + done >expected && mv file1 file2 && git update-index --add --remove file1 file2 && @@ -53,25 +59,30 @@ test_expect_success 'apply without --reject should fail' ' test_expect_success 'apply with --reject should fail but update the file' ' - cat saved.file1 >file1 + cat saved.file1 >file1 && + rm -f file1.rej file2.rej && - if git apply --reject patch.1 >rejects + if git apply --reject patch.1 then echo "succeeds with --reject?" exit 1 fi - cat rejects - for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 - do - echo $i - done >expected.file1 && - diff -u file1 expected.file1 + diff -u file1 expected && + + cat file1.rej && + + if test -f file2.rej + then + echo "file2 should not have been touched" + exit 1 + fi ' test_expect_success 'apply with --reject should fail but update the file' ' - cat saved.file1 >file1 + cat saved.file1 >file1 && + rm -f file1.rej file2.rej file2 && if git apply --reject patch.2 >rejects then @@ -79,18 +90,20 @@ test_expect_success 'apply with --reject should fail but update the file' ' exit 1 fi - cat rejects - - for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 - do - echo $i - done >expected.file2 && - test -f file1 && { echo "file1 still exists?" exit 1 } - diff -u file2 expected.file2 + diff -u file2 expected && + + cat file2.rej && + + if test -f file1.rej + then + echo "file2 should not have been touched" + exit 1 + fi + ' test_done -- cgit v1.2.1 From a2bf404e280b8d56d0efa15bd9700464cf8f0d4d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 18 Aug 2006 03:14:48 -0700 Subject: git-apply --verbose Signed-off-by: Junio C Hamano --- t/t4117-apply-reject.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 't') diff --git a/t/t4117-apply-reject.sh b/t/t4117-apply-reject.sh index 1cf9a2e7a7..b4de075a3e 100755 --- a/t/t4117-apply-reject.sh +++ b/t/t4117-apply-reject.sh @@ -57,6 +57,17 @@ test_expect_success 'apply without --reject should fail' ' diff -u file1 saved.file1 ' +test_expect_success 'apply without --reject should fail' ' + + if git apply --verbose patch.1 + then + echo "Eh? Why?" + exit 1 + fi + + diff -u file1 saved.file1 +' + test_expect_success 'apply with --reject should fail but update the file' ' cat saved.file1 >file1 && @@ -106,4 +117,41 @@ test_expect_success 'apply with --reject should fail but update the file' ' ' +test_expect_success 'the same test with --verbose' ' + + cat saved.file1 >file1 && + rm -f file1.rej file2.rej file2 && + + if git apply --reject --verbose patch.2 >rejects + then + echo "succeeds with --reject?" + exit 1 + fi + + test -f file1 && { + echo "file1 still exists?" + exit 1 + } + diff -u file2 expected && + + cat file2.rej && + + if test -f file1.rej + then + echo "file2 should not have been touched" + exit 1 + fi + +' + +test_expect_success 'apply cleanly with --verbose' ' + + git cat-file -p HEAD:file1 >file1 && + rm -f file?.rej file2 && + + git apply --verbose patch.1 && + + diff -u file1 clean +' + test_done -- cgit v1.2.1