3 ## applypatch takes four file arguments, and uses those to
4 ## apply the unpacked patch (surprise surprise) that they
5 ## represent to the current tree.
8 ## $1 - file with commit message
9 ## $2 - file with the actual patch
10 ## $3 - "info" file with Author, email and subject
11 ## $4 - optional file containing signoff to add
13 . git-sh-setup || die
"Not a git archive."
15 final
=.dotest
/final-commit
17 ## If this file exists, we ask before applying
19 query_apply
=.dotest
/.query_apply
21 ## We do not munge the first line of the commit message too much
22 ## if this file exists.
23 keep_subject
=.dotest
/.keep_subject
30 EDIT
=${VISUAL:-${EDITOR:-vi}}
32 export GIT_AUTHOR_NAME
="$(sed -n '/^Author/ s/Author: //p' .dotest/info)"
33 export GIT_AUTHOR_EMAIL
="$(sed -n '/^Email/ s/Email: //p' .dotest/info)"
34 export GIT_AUTHOR_DATE
="$(sed -n '/^Date/ s/Date: //p' .dotest/info)"
35 export SUBJECT
="$(sed -n '/^Subject/ s/Subject: //p' .dotest/info)"
37 if test '' != "$SIGNOFF"
41 SIGNOFF
=`cat "$SIGNOFF"` ||
exit
42 elif case "$SIGNOFF" in yes | true | me | please
) : ;; *) false
;; esac
44 SIGNOFF
=`git-var GIT_COMMITTER_IDENT | sed -e '
51 if test '' != "$SIGNOFF"
54 sed -ne '/^Signed-off-by: /p' "$MSGFILE" |
57 test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" ||
58 echo "$SIGNOFF" >>"$MSGFILE"
63 test -f "$keep_subject" || patch_header
='[PATCH] '
66 echo "$patch_header$SUBJECT"
75 test -f "$query_apply" || interactive
=no
77 while [ "$interactive" = yes ]; do
78 echo "Commit Body is:"
79 echo "--------------------------"
81 echo "--------------------------"
82 echo -n "Apply? [y]es/[n]o/[e]dit/[a]ccept all "
86 n|N
) exit 2;; # special value to tell dotest to keep going
87 e|E
) "$EDIT" "$final";;
88 a|A
) rm -f "$query_apply"
93 if test -x "$GIT_DIR"/hooks
/applypatch-msg
95 "$GIT_DIR"/hooks
/applypatch-msg
"$final" ||
exit
99 echo Applying
"'$SUBJECT'"
102 git-apply
--index "$PATCHFILE" ||
exit 1
104 if test -x "$GIT_DIR"/hooks
/pre-applypatch
106 "$GIT_DIR"/hooks
/pre-applypatch ||
exit
109 tree
=$
(git-write-tree
) ||
exit 1
110 echo Wrote tree
$tree
111 commit
=$
(git-commit-tree
$tree -p $
(cat "$GIT_DIR"/HEAD
) < "$final") ||
exit 1
112 echo Committed
: $commit
113 echo $commit > "$GIT_DIR"/HEAD
115 if test -x "$GIT_DIR"/hooks
/post-applypatch
117 "$GIT_DIR"/hooks
/post-applypatch