aboutsummaryrefslogtreecommitdiff
path: root/git-apply-patch-script
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-05-04 01:38:06 -0700
committerJunio C Hamano <junkio@cox.net>2005-05-04 01:38:06 -0700
commit6fa28064b0c9da9c2c8696b4eac28ee5beaee469 (patch)
tree514741f37d09ebcbef1758e90391a7857be90ccd /git-apply-patch-script
parentae7c0c92c0713307986bcd1fb54fa0694aae962a (diff)
downloadgit-6fa28064b0c9da9c2c8696b4eac28ee5beaee469.tar.gz
git-6fa28064b0c9da9c2c8696b4eac28ee5beaee469.tar.xz
Terminate diff-* on non-zero exit from GIT_EXTERNAL_DIFF
(slightly updated from the version posted to the GIT mailing list with small bugfixes). This patch changes the git-apply-patch-script to exit non-zero when the patch cannot be applied. Previously, the external diff driver deliberately ignored the exit status of GIT_EXTERNAL_DIFF command, which was a design mistake. It now stops the processing when GIT_EXTERNAL_DIFF exits non-zero, so the damages from running git-diff-* with git-apply-patch-script between two wrong trees can be contained. The "diff" command line generated by the built-in driver is changed to always exit 0 in order to match this new behaviour. I know Pasky does not use GIT_EXTERNAL_DIFF yet, so this change should not break Cogito, either. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-apply-patch-script')
-rwxr-xr-xgit-apply-patch-script75
1 files changed, 43 insertions, 32 deletions
diff --git a/git-apply-patch-script b/git-apply-patch-script
index c28015aad..29548ba6a 100755
--- a/git-apply-patch-script
+++ b/git-apply-patch-script
@@ -19,40 +19,51 @@ then
echo >&2 "Unresolved patch conflicts in the previous run found."
exit 1
fi
-# This will say "patching ..." so we do not say anything outselves.
-diff -u -L "a/$name" -L "b/$name" "$tmp1" "$tmp2" | patch -p1
-test -f "$name.rej" || {
- case "$mode1,$mode2" in
- .,?x)
- # newly created
- case "$mode2" in
- +x)
- echo >&2 "created $name with mode +x."
- chmod "$mode2" "$name"
- ;;
- -x)
- echo >&2 "created $name."
- ;;
- esac
- git-update-cache --add -- "$name"
+case "$mode1,$mode2" in
+.,?x)
+ # newly created
+ dir=$(dirname "$name")
+ case "$dir" in '' | .) ;; *) mkdir -p "$dir" esac || {
+ echo >&2 "cannot create leading path for $name."
+ exit 1
+ }
+ case "$mode2" in
+ +x)
+ echo >&2 "created $name with mode +x."
+ chmod "$mode2" "$name"
;;
- ?x,.)
- # deleted
- echo >&2 "deleted $name."
- rm -f "$name"
- git-update-cache --remove -- "$name"
+ -x)
+ echo >&2 "created $name."
;;
+ esac
+ git-update-cache --add -- "$name"
+ ;;
+?x,.)
+ # deleted
+ echo >&2 "deleted $name."
+ rm -f "$name" || {
+ echo >&2 "cannot remove $name";
+ exit 1
+ }
+ git-update-cache --remove -- "$name"
+ ;;
+*)
+ # changed
+ dir=$(dirname "$name")
+ case "$dir" in '' | .) ;; *) mkdir -p "$dir" esac || {
+ echo >&2 "cannot create leading path for $name."
+ exit 1
+ }
+ # This will say "patching ..." so we do not say anything outselves.
+ diff -u -L "a/$name" -L "b/$name" "$tmp1" "$tmp2" | patch -p1 || exit
+
+ case "$mode1,$mode2" in
+ "$mode2,$mode1") ;;
*)
- # changed
- case "$mode1,$mode2" in
- "$mode2,$mode1") ;;
- *)
- echo >&2 "changing mode from $mode1 to $mode2."
- chmod "$mode2" "$name"
- ;;
- esac
- git-update-cache -- "$name"
+ echo >&2 "changing mode from $mode1 to $mode2."
+ chmod "$mode2" "$name"
+ ;;
esac
-}
-exit 0
+ git-update-cache -- "$name"
+esac