]> git.ipfire.org Git - thirdparty/git.git/blame - git-applymbox
GIT 0.99.6
[thirdparty/git.git] / git-applymbox
CommitLineData
853916ff
LT
1#!/bin/sh
2##
3## "dotest" is my stupid name for my patch-application script, which
4## I never got around to renaming after I tested it. We're now on the
5## second generation of scripts, still called "dotest".
6##
c5f7674a
LT
7## Update: Ryan Anderson finally shamed me into naming this "applymbox".
8##
853916ff
LT
9## You give it a mbox-format collection of emails, and it will try to
10## apply them to the kernel using "applypatch"
11##
d4a9ce78 12## applymbox [-u] [-k] [-q] (-c .dotest/msg-number | mail_archive) [Signoff_file]"
ad4e9ce4 13##
37275318
JH
14## The patch application may fail in the middle. In which case:
15## (1) look at .dotest/patch and fix it up to apply
16## (2) re-run applymbox with -c .dotest/msg-number for the current one.
17## Pay a special attention to the commit log message if you do this and
18## use a Signoff_file, because applypatch wants to append the sign-off
19## message to msg-clean every time it is run.
ad4e9ce4 20
d571c2be
LT
21. git-sh-setup-script || die "Not a git archive"
22
d4a9ce78
JH
23usage () {
24 echo >&2 "applymbox [-u] [-k] [-q] (-c .dotest/<num> | mbox) [signoff]"
25 exit 1
26}
27
28keep_subject= query_apply= continue= utf8= resume=t
37275318
JH
29while case "$#" in 0) break ;; esac
30do
31 case "$1" in
d4a9ce78 32 -u) utf8=-u ;;
6bff6a60 33 -k) keep_subject=-k ;;
37275318
JH
34 -q) query_apply=t ;;
35 -c) continue="$2"; resume=f; shift ;;
36 -*) usage ;;
37 *) break ;;
38 esac
39 shift
40done
41
42case "$continue" in
43'')
44 rm -rf .dotest
45 mkdir .dotest
154d3d2d 46 git-mailsplit "$1" .dotest || exit 1
b50abe88 47 shift
ad4e9ce4 48esac
37275318 49
d571c2be
LT
50files=$(git-diff-cache --cached --name-only HEAD) || exit
51if [ "$files" ]; then
52 echo "Dirty index: cannot apply patches (dirty: $files)" >&2
53 exit 1
54fi
55
37275318
JH
56case "$query_apply" in
57t) touch .dotest/.query_apply
58esac
6bff6a60
JH
59case "$keep_subject" in
60-k) : >.dotest/.keep_subject
61esac
37275318 62
b50abe88
JH
63signoff="$1"
64set x .dotest/0*
65shift
66while case "$#" in 0) break;; esac
853916ff 67do
b50abe88
JH
68 i="$1"
69 case "$resume,$continue" in
70 f,$i) resume=t;;
07a95d0e
JH
71 f,*) shift
72 continue;;
b50abe88 73 *)
d4a9ce78 74 git-mailinfo $keep_subject $utf8 \
6bff6a60 75 .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
b50abe88
JH
76 git-stripspace < .dotest/msg > .dotest/msg-clean
77 ;;
78 esac
79 while :; # for fixing up and retry
80 do
81 git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff"
82 case "$?" in
83 0 | 2 )
ad4e9ce4
JB
84 # 2 is a special exit code from applypatch to indicate that
85 # the patch wasn't applied, but continue anyway
b50abe88
JH
86 ;;
87 *)
88 ret=$?
89 if test -f .dotest/.query_apply
90 then
91 echo >&2 "* Patch failed."
92 echo >&2 "* You could fix it up in your editor and"
93 echo >&2 " retry. If you want to do so, say yes here"
94 echo >&2 " AFTER fixing .dotest/patch up."
95 echo >&2 -n "Retry [y/N]? "
96 read yesno
97 case "$yesno" in
98 [Yy]*)
99 continue ;;
100 esac
101 fi
102 exit $ret
103 esac
104 break
105 done
106 shift
853916ff 107done
ad4e9ce4
JB
108# return to pristine
109rm -fr .dotest