-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply --unidiff-zero: loosen sanity checks for --unidiff=0 patches
In "git-apply", we have a few sanity checks and heuristics that expects that the patch fed to us is a unified diff with at least one line of context. * When there is no leading context line in a hunk, the hunk must apply at the beginning of the preimage. Similarly, no trailing context means that the hunk is anchored at the end. * We learn a patch deletes the file from a hunk that has no resulting line (i.e. all lines are prefixed with '-') if it has not otherwise been known if the patch deletes the file. Similarly, no old line means the file is being created. And we declare an error condition when the file created by a creation patch already exists, and/or when a deletion patch still leaves content in the file. These sanity checks are good safety measures, but breaks down when people feed a diff generated with --unified=0. This was recently noticed first by Matthew Wilcox and Gerrit Pape. This adds a new flag, --unified-zero, to allow bypassing these checks. If you are in control of the patch generation process, you should not use --unified=0 patch and fix it up with this flag; rather you should try work with a patch with context. But if all you have to work with is a patch without context, this flag may come handy as the last resort. Signed-off-by: Junio C Hamano <junkio@cox.net>
- Loading branch information
Junio C Hamano
committed
Sep 17, 2006
1 parent
8aac4b4
commit 4be6096
Showing
3 changed files
with
197 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright (c) 2005 Junio C Hamano | ||
# | ||
|
||
test_description='git-apply boundary tests | ||
' | ||
. ./test-lib.sh | ||
|
||
L="c d e f g h i j k l m n o p q r s t u v w x" | ||
|
||
test_expect_success setup ' | ||
for i in b '"$L"' y | ||
do | ||
echo $i | ||
done >victim && | ||
cat victim >original && | ||
git update-index --add victim && | ||
: add to the head | ||
for i in a b '"$L"' y | ||
do | ||
echo $i | ||
done >victim && | ||
cat victim >add-a-expect && | ||
git diff victim >add-a-patch.with && | ||
git diff --unified=0 >add-a-patch.without && | ||
: modify at the head | ||
for i in a '"$L"' y | ||
do | ||
echo $i | ||
done >victim && | ||
cat victim >mod-a-expect && | ||
git diff victim >mod-a-patch.with && | ||
git diff --unified=0 >mod-a-patch.without && | ||
: remove from the head | ||
for i in '"$L"' y | ||
do | ||
echo $i | ||
done >victim && | ||
cat victim >del-a-expect && | ||
git diff victim >del-a-patch.with | ||
git diff --unified=0 >del-a-patch.without && | ||
: add to the tail | ||
for i in b '"$L"' y z | ||
do | ||
echo $i | ||
done >victim && | ||
cat victim >add-z-expect && | ||
git diff victim >add-z-patch.with && | ||
git diff --unified=0 >add-z-patch.without && | ||
: modify at the tail | ||
for i in a '"$L"' y | ||
do | ||
echo $i | ||
done >victim && | ||
cat victim >mod-z-expect && | ||
git diff victim >mod-z-patch.with && | ||
git diff --unified=0 >mod-z-patch.without && | ||
: remove from the tail | ||
for i in b '"$L"' | ||
do | ||
echo $i | ||
done >victim && | ||
cat victim >del-z-expect && | ||
git diff victim >del-z-patch.with | ||
git diff --unified=0 >del-z-patch.without && | ||
: done | ||
' | ||
|
||
for with in with without | ||
do | ||
case "$with" in | ||
with) u= ;; | ||
without) u='--unidiff-zero ' ;; | ||
esac | ||
for kind in add-a add-z mod-a mod-z del-a del-z | ||
do | ||
test_expect_success "apply $kind-patch $with context" ' | ||
cat original >victim && | ||
git update-index victim && | ||
git apply --index '"$u$kind-patch.$with"' || { | ||
cat '"$kind-patch.$with"' | ||
(exit 1) | ||
} && | ||
diff -u '"$kind"'-expect victim | ||
' | ||
done | ||
done | ||
|
||
for kind in add-a add-z mod-a mod-z del-a del-z | ||
do | ||
rm -f $kind-ng.without | ||
sed -e "s/^diff --git /diff /" \ | ||
-e '/^index /d' \ | ||
<$kind-patch.without >$kind-ng.without | ||
test_expect_success "apply non-git $kind-patch without context" ' | ||
cat original >victim && | ||
git update-index victim && | ||
git apply --unidiff-zero --index '"$kind-ng.without"' || { | ||
cat '"$kind-ng.without"' | ||
(exit 1) | ||
} && | ||
diff -u '"$kind"'-expect victim | ||
' | ||
done | ||
|
||
test_done |