]> git.ipfire.org Git - thirdparty/git.git/blame - git-applymbox.sh
Makefile: Remove git-fsck and git-verify-pack from PROGRAMS
[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
e3b59a44
JH
24git var GIT_COMMITTER_IDENT >/dev/null || exit
25
62c89c66 26keep_subject= query_apply= continue= utf8=-u resume=t
37275318
JH
27while case "$#" in 0) break ;; esac
28do
29 case "$1" in
d4a9ce78 30 -u) utf8=-u ;;
bb1091a4 31 -n) utf8=-n ;;
6bff6a60 32 -k) keep_subject=-k ;;
37275318
JH
33 -q) query_apply=t ;;
34 -c) continue="$2"; resume=f; shift ;;
e1355547 35 -m) fall_back_3way=t ;;
37275318
JH
36 -*) usage ;;
37 *) break ;;
38 esac
39 shift
40done
41
42case "$continue" in
43'')
44 rm -rf .dotest
45 mkdir .dotest
e11fc020
JH
46 num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
47 echo "$num_msgs patch(es) to process."
b50abe88 48 shift
ad4e9ce4 49esac
37275318 50
215a7ad1 51files=$(git-diff-index --cached --name-only HEAD) || exit
d571c2be
LT
52if [ "$files" ]; then
53 echo "Dirty index: cannot apply patches (dirty: $files)" >&2
54 exit 1
55fi
56
37275318
JH
57case "$query_apply" in
58t) touch .dotest/.query_apply
59esac
47f0b6d5
JH
60case "$fall_back_3way" in
61t) : >.dotest/.3way
62esac
6bff6a60
JH
63case "$keep_subject" in
64-k) : >.dotest/.keep_subject
65esac
37275318 66
b50abe88
JH
67signoff="$1"
68set x .dotest/0*
69shift
70while case "$#" in 0) break;; esac
853916ff 71do
b50abe88
JH
72 i="$1"
73 case "$resume,$continue" in
74 f,$i) resume=t;;
07a95d0e
JH
75 f,*) shift
76 continue;;
b50abe88 77 *)
d4a9ce78 78 git-mailinfo $keep_subject $utf8 \
6bff6a60 79 .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
0d38ab25 80 test -s .dotest/patch || {
7d4f4a2f 81 echo "Patch is empty. Was it split wrong?"
0d38ab25 82 exit 1
87ab7992 83 }
b50abe88
JH
84 git-stripspace < .dotest/msg > .dotest/msg-clean
85 ;;
86 esac
87 while :; # for fixing up and retry
88 do
89 git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff"
90 case "$?" in
4ebe63df
JH
91 0)
92 # Remove the cleanly applied one to reduce clutter.
93 rm -f .dotest/$i
94 ;;
95 2)
ad4e9ce4
JB
96 # 2 is a special exit code from applypatch to indicate that
97 # the patch wasn't applied, but continue anyway
b50abe88
JH
98 ;;
99 *)
100 ret=$?
101 if test -f .dotest/.query_apply
102 then
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]? "
108 read yesno
109 case "$yesno" in
110 [Yy]*)
111 continue ;;
112 esac
113 fi
114 exit $ret
115 esac
116 break
117 done
118 shift
853916ff 119done
ad4e9ce4
JB
120# return to pristine
121rm -fr .dotest