2 # Copyright (C) 2005 Junio C Hamano
4 # Applying diff between two trees to the work tree can be
5 # done with the following single command:
7 # GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p $tree1 $tree2
11 2) exit 1 ;; # do not feed unmerged diff to me!
13 name="$1" tmp1="$2" hex1="$3" mode1="$4" tmp2="$5" hex2="$6" mode2="$7"
14 case "$mode1" in *7??) mode1=+x ;; *6??) mode1=-x ;; esac
15 case "$mode2" in *7??) mode2=+x ;; *6??) mode2=-x ;; esac
17 if test -f "$name.orig" || test -f "$name.rej"
19 echo >&2 "Unresolved patch conflicts in the previous run found."
23 case "$mode1,$mode2" in
26 dir=$(dirname "$name")
27 case "$dir" in '' | .) ;; *) mkdir -p "$dir" esac || {
28 echo >&2 "cannot create leading path for $name."
33 echo >&2 "created $name with mode +x."
34 chmod "$mode2" "$name"
37 echo >&2 "created $name."
40 git-update-cache --add -- "$name"
44 echo >&2 "deleted $name."
46 echo >&2 "cannot remove $name";
49 git-update-cache --remove -- "$name"
53 dir=$(dirname "$name")
54 case "$dir" in '' | .) ;; *) mkdir -p "$dir" esac || {
55 echo >&2 "cannot create leading path for $name."
58 # This will say "patching ..." so we do not say anything outselves.
59 diff -u -L "a/$name" -L "b/$name" "$tmp1" "$tmp2" | patch -p1 || exit
61 case "$mode1,$mode2" in
64 echo >&2 "changing mode from $mode1 to $mode2."
65 chmod "$mode2" "$name"
68 git-update-cache -- "$name"