]> git.ipfire.org Git - thirdparty/git.git/blame - git-applymbox.sh
t3200: branch --help does not die anymore.
[thirdparty/git.git] / git-applymbox.sh
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##
37275318
JH
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.
42e2cba2
PB
18##
19## git-am is supposed to be the newer and better tool for this job.
ad4e9ce4 20
ae2b0f15 21. git-sh-setup
d571c2be 22
d4a9ce78 23usage () {
47f0b6d5 24 echo >&2 "applymbox [-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]"
d4a9ce78
JH
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 ;;
e1355547 36 -m) fall_back_3way=t ;;
37275318
JH
37 -*) usage ;;
38 *) break ;;
39 esac
40 shift
41done
42
43case "$continue" in
44'')
45 rm -rf .dotest
46 mkdir .dotest
e11fc020
JH
47 num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
48 echo "$num_msgs patch(es) to process."
b50abe88 49 shift
ad4e9ce4 50esac
37275318 51
215a7ad1 52files=$(git-diff-index --cached --name-only HEAD) || exit
d571c2be
LT
53if [ "$files" ]; then
54 echo "Dirty index: cannot apply patches (dirty: $files)" >&2
55 exit 1
56fi
57
37275318
JH
58case "$query_apply" in
59t) touch .dotest/.query_apply
60esac
47f0b6d5
JH
61case "$fall_back_3way" in
62t) : >.dotest/.3way
63esac
6bff6a60
JH
64case "$keep_subject" in
65-k) : >.dotest/.keep_subject
66esac
37275318 67
b50abe88
JH
68signoff="$1"
69set x .dotest/0*
70shift
71while case "$#" in 0) break;; esac
853916ff 72do
b50abe88
JH
73 i="$1"
74 case "$resume,$continue" in
75 f,$i) resume=t;;
07a95d0e
JH
76 f,*) shift
77 continue;;
b50abe88 78 *)
d4a9ce78 79 git-mailinfo $keep_subject $utf8 \
6bff6a60 80 .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
b50abe88
JH
81 git-stripspace < .dotest/msg > .dotest/msg-clean
82 ;;
83 esac
84 while :; # for fixing up and retry
85 do
86 git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff"
87 case "$?" in
4ebe63df
JH
88 0)
89 # Remove the cleanly applied one to reduce clutter.
90 rm -f .dotest/$i
91 ;;
92 2)
ad4e9ce4
JB
93 # 2 is a special exit code from applypatch to indicate that
94 # the patch wasn't applied, but continue anyway
b50abe88
JH
95 ;;
96 *)
97 ret=$?
98 if test -f .dotest/.query_apply
99 then
100 echo >&2 "* Patch failed."
101 echo >&2 "* You could fix it up in your editor and"
102 echo >&2 " retry. If you want to do so, say yes here"
103 echo >&2 " AFTER fixing .dotest/patch up."
104 echo >&2 -n "Retry [y/N]? "
105 read yesno
106 case "$yesno" in
107 [Yy]*)
108 continue ;;
109 esac
110 fi
111 exit $ret
112 esac
113 break
114 done
115 shift
853916ff 116done
ad4e9ce4
JB
117# return to pristine
118rm -fr .dotest