]>
Commit | Line | Data |
---|---|---|
853916ff LT |
1 | #!/bin/sh |
2 | ## | |
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. | |
6 | ## | |
7 | ## The arguments are: | |
8 | ## $1 - file with commit message | |
9 | ## $2 - file with the actual patch | |
a196d8d4 LT |
10 | ## $3 - "info" file with Author, email and subject |
11 | ## $4 - optional file containing signoff to add | |
853916ff | 12 | ## |
215a7ad1 | 13 | . git-sh-setup || die "Not a git archive." |
4426ac70 | 14 | |
ad4e9ce4 JB |
15 | final=.dotest/final-commit |
16 | ## | |
17 | ## If this file exists, we ask before applying | |
18 | ## | |
19 | query_apply=.dotest/.query_apply | |
4426ac70 JH |
20 | |
21 | ## We do not munge the first line of the commit message too much | |
22 | ## if this file exists. | |
6bff6a60 | 23 | keep_subject=.dotest/.keep_subject |
4426ac70 JH |
24 | |
25 | ||
853916ff LT |
26 | MSGFILE=$1 |
27 | PATCHFILE=$2 | |
a196d8d4 | 28 | INFO=$3 |
4426ac70 JH |
29 | SIGNOFF=$4 |
30 | EDIT=${VISUAL:-${EDITOR:-vi}} | |
ad4e9ce4 | 31 | |
c9049d41 LT |
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)" | |
853916ff LT |
35 | export SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' .dotest/info)" |
36 | ||
4426ac70 JH |
37 | if test '' != "$SIGNOFF" |
38 | then | |
39 | if test -f "$SIGNOFF" | |
40 | then | |
41 | SIGNOFF=`cat "$SIGNOFF"` || exit | |
42 | elif case "$SIGNOFF" in yes | true | me | please) : ;; *) false ;; esac | |
43 | then | |
44 | SIGNOFF=`git-var GIT_COMMITTER_IDENT | sed -e ' | |
45 | s/>.*/>/ | |
46 | s/^/Signed-off-by: /' | |
47 | ` | |
48 | else | |
49 | SIGNOFF= | |
50 | fi | |
51 | if test '' != "$SIGNOFF" | |
52 | then | |
53 | LAST_SIGNED_OFF_BY=` | |
54 | sed -ne '/^Signed-off-by: /p' "$MSGFILE" | | |
55 | tail -n 1 | |
56 | ` | |
57 | test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || | |
58 | echo "$SIGNOFF" >>"$MSGFILE" | |
59 | fi | |
ad4e9ce4 | 60 | fi |
4426ac70 | 61 | |
6bff6a60 JH |
62 | patch_header= |
63 | test -f "$keep_subject" || patch_header='[PATCH] ' | |
ad4e9ce4 | 64 | |
4426ac70 JH |
65 | { |
66 | echo "$patch_header$SUBJECT" | |
67 | if test -s "$MSGFILE" | |
68 | then | |
69 | echo | |
70 | cat "$MSGFILE" | |
71 | fi | |
72 | } >"$final" | |
ad4e9ce4 | 73 | |
4426ac70 JH |
74 | interactive=yes |
75 | test -f "$query_apply" || interactive=no | |
ad4e9ce4 | 76 | |
4426ac70 | 77 | while [ "$interactive" = yes ]; do |
ad4e9ce4 JB |
78 | echo "Commit Body is:" |
79 | echo "--------------------------" | |
4426ac70 | 80 | cat "$final" |
ad4e9ce4 JB |
81 | echo "--------------------------" |
82 | echo -n "Apply? [y]es/[n]o/[e]dit/[a]ccept all " | |
83 | read reply | |
4426ac70 JH |
84 | case "$reply" in |
85 | y|Y) interactive=no;; | |
ad4e9ce4 | 86 | n|N) exit 2;; # special value to tell dotest to keep going |
4426ac70 JH |
87 | e|E) "$EDIT" "$final";; |
88 | a|A) rm -f "$query_apply" | |
89 | interactive=no ;; | |
ad4e9ce4 JB |
90 | esac |
91 | done | |
92 | ||
4426ac70 JH |
93 | if test -x "$GIT_DIR"/hooks/applypatch-msg |
94 | then | |
95 | "$GIT_DIR"/hooks/applypatch-msg "$final" || exit | |
96 | fi | |
97 | ||
853916ff | 98 | echo |
61096819 | 99 | echo Applying "'$SUBJECT'" |
853916ff LT |
100 | echo |
101 | ||
4426ac70 JH |
102 | git-apply --index "$PATCHFILE" || exit 1 |
103 | ||
104 | if test -x "$GIT_DIR"/hooks/pre-applypatch | |
105 | then | |
106 | "$GIT_DIR"/hooks/pre-applypatch || exit | |
107 | fi | |
108 | ||
50eb31d1 | 109 | tree=$(git-write-tree) || exit 1 |
853916ff | 110 | echo Wrote tree $tree |
bf7960eb JH |
111 | parent=$(git-rev-parse --verify HEAD) && |
112 | commit=$(git-commit-tree $tree -p $parent <"$final") || exit 1 | |
853916ff | 113 | echo Committed: $commit |
bf7960eb | 114 | git-update-ref HEAD $commit $parent || exit |
4426ac70 JH |
115 | |
116 | if test -x "$GIT_DIR"/hooks/post-applypatch | |
117 | then | |
118 | "$GIT_DIR"/hooks/post-applypatch | |
119 | fi |