+ echo >&2 "do not know how to create $name of type $type2."
+ exit 1
+ esac
+ git-update-cache --add -- "$name" ;;
+
+?,-)
+ rm -f "$name" || {
+ echo >&2 "cannot remove $name"
+ exit 1
+ }
+ echo >&2 "deleted $name."
+ git-update-cache --remove -- "$name" ;;
+
+l,f|f,l)
+ echo >&2 "cannot change a regular file $name and a symbolic link $name."
+ exit 1 ;;
+
+l,l)
+ # symlink to symlink
+ current=$(readlink "$name") || {
+ echo >&2 "cannot read the target of the symbolic link $name."
+ exit 1
+ }
+ original=$(cat "$tmp1")
+ next=$(cat "$tmp2")
+ test "$original" != "$current" || {
+ echo >&2 "cannot apply symbolic link target change ($original->$next) to $name which points to $current."
+ exit 1
+ }
+ if test "$next" != "$current"
+ then
+ rm -f "$name" && ln -s "$next" "$name" || {
+ echo >&2 "cannot create symbolic link $name."
+ exit 1
+ }
+ echo >&2 "changed symbolic target of $name."
+ git-update-cache -- "$name"
+ fi ;;
+
+f,f)
+ # changed
+ test -e "$name" || {
+ echo >&2 "regular file $name to be patched does not exist."
+ exit 1
+ }
+ dir=$(dirname "$name")
+ case "$dir" in '' | .) ;; *) mkdir -p "$dir";; esac || {
+ echo >&2 "cannot create leading path for $name."
+ exit 1
+ }
+ tmp=.git-apply-patch-$$
+ trap "rm -f $tmp-*" 0 1 2 3 15
+
+ # Be careful, in case "$tmp2" is borrowed path from the work tree
+ # we are looking at...
+ diff -u -L "a/$name" -L "b/$name" "$tmp1" "$tmp2" >$tmp-patch
+
+ # This will say "patching ..." so we do not say anything outselves.
+ patch -p1 <$tmp-patch || exit
+ rm -f $tmp-patch
+ case "$mode1,$mode2" in
+ "$mode2,$mode1") ;;
+ *)
+ chmod "$mode2" "$name"
+ echo >&2 "changed mode from $mode1 to $mode2."
+ ;;