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".
7 ## Update: Ryan Anderson finally shamed me into naming this "applymbox".
9 ## You give it a mbox-format collection of emails, and it will try to
10 ## apply them to the kernel using "applypatch"
12 ## The patch application may fail in the middle. In which case:
13 ## (1) look at .dotest/patch and fix it up to apply
14 ## (2) re-run applymbox with -c .dotest/msg-number for the current one.
15 ## Pay a special attention to the commit log message if you do this and
16 ## use a Signoff_file, because applypatch wants to append the sign-off
17 ## message to msg-clean every time it is run.
19 ## git-am is supposed to be the newer and better tool for this job.
21 USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]'
24 git var GIT_COMMITTER_IDENT >/dev/null || exit
26 keep_subject= query_apply= continue= utf8=-u resume=t
27 while case "$#" in 0) break ;; esac
32 -k) keep_subject=-k ;;
34 -c) continue="$2"; resume=f; shift ;;
35 -m) fall_back_3way=t ;;
46 num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
47 echo "$num_msgs patch(es) to process."
51 files=$(git-diff-index --cached --name-only HEAD) || exit
53 echo "Dirty index: cannot apply patches (dirty: $files)" >&2
57 case "$query_apply" in
58 t) touch .dotest/.query_apply
60 case "$fall_back_3way" in
63 case "$keep_subject" in
64 -k) : >.dotest/.keep_subject
70 while case "$#" in 0) break;; esac
73 case "$resume,$continue" in
78 git-mailinfo $keep_subject $utf8 \
79 .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
80 test -s .dotest/patch || {
81 echo "Patch is empty. Was it split wrong?"
84 git-stripspace < .dotest/msg > .dotest/msg-clean
87 while :; # for fixing up and retry
89 git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff"
92 # Remove the cleanly applied one to reduce clutter.
96 # 2 is a special exit code from applypatch to indicate that
97 # the patch wasn't applied, but continue anyway
101 if test -f .dotest/.query_apply
103 echo >&2 "* Patch failed."
104 echo >&2 "* You could fix it up in your editor and"
105 echo >&2 " retry. If you want to do so, say yes here"
106 echo >&2 " AFTER fixing .dotest/patch up."
107 echo >&2 -n "Retry [y/N]? "