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