]> git.ipfire.org Git - thirdparty/git.git/blame - tools/git-applymbox
Document "git cherry-pick" and "git revert"
[thirdparty/git.git] / tools / 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##
6bff6a60 12## applymbox [ -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
6bff6a60 23keep_subject= query_apply= continue= resume=t
37275318
JH
24while case "$#" in 0) break ;; esac
25do
26 case "$1" in
6bff6a60 27 -k) keep_subject=-k ;;
37275318
JH
28 -q) query_apply=t ;;
29 -c) continue="$2"; resume=f; shift ;;
30 -*) usage ;;
31 *) break ;;
32 esac
33 shift
34done
35
36case "$continue" in
37'')
38 rm -rf .dotest
39 mkdir .dotest
154d3d2d 40 git-mailsplit "$1" .dotest || exit 1
b50abe88 41 shift
ad4e9ce4 42esac
37275318 43
d571c2be
LT
44files=$(git-diff-cache --cached --name-only HEAD) || exit
45if [ "$files" ]; then
46 echo "Dirty index: cannot apply patches (dirty: $files)" >&2
47 exit 1
48fi
49
37275318
JH
50case "$query_apply" in
51t) touch .dotest/.query_apply
52esac
6bff6a60
JH
53case "$keep_subject" in
54-k) : >.dotest/.keep_subject
55esac
37275318 56
b50abe88
JH
57signoff="$1"
58set x .dotest/0*
59shift
60while case "$#" in 0) break;; esac
853916ff 61do
b50abe88
JH
62 i="$1"
63 case "$resume,$continue" in
64 f,$i) resume=t;;
65 f,*) continue;;
66 *)
6bff6a60
JH
67 git-mailinfo $keep_subject \
68 .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
b50abe88
JH
69 git-stripspace < .dotest/msg > .dotest/msg-clean
70 ;;
71 esac
72 while :; # for fixing up and retry
73 do
74 git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff"
75 case "$?" in
76 0 | 2 )
ad4e9ce4
JB
77 # 2 is a special exit code from applypatch to indicate that
78 # the patch wasn't applied, but continue anyway
b50abe88
JH
79 ;;
80 *)
81 ret=$?
82 if test -f .dotest/.query_apply
83 then
84 echo >&2 "* Patch failed."
85 echo >&2 "* You could fix it up in your editor and"
86 echo >&2 " retry. If you want to do so, say yes here"
87 echo >&2 " AFTER fixing .dotest/patch up."
88 echo >&2 -n "Retry [y/N]? "
89 read yesno
90 case "$yesno" in
91 [Yy]*)
92 continue ;;
93 esac
94 fi
95 exit $ret
96 esac
97 break
98 done
99 shift
853916ff 100done
ad4e9ce4
JB
101# return to pristine
102rm -fr .dotest