-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit-cherry-pick-list
executable file
·100 lines (89 loc) · 2.01 KB
/
git-cherry-pick-list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
#
# Copyright (C) 2016 Konsulko Group
# Author: Pantelis Antoniou
#
# https://www.konsulko.com/git-workflow-for-upstreaming-patches-from-a-vendor-kernel-2/
#
set -o errexit
usage() {
echo "usage: git cherry-pick-list [-h|-s] patchlist.txt"
echo " generate patchlist: git log --oneline --reverse master..bar | tee patchlist.txt"
echo -e "\t-s, --signoff\t\tadd Signed-off-by:"
}
opts=`getopt --options hs --long help,signoff -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
eval set -- "$opts"
with_signoff=false
while [[ $# != 0 ]]; do
case "$1" in
-h|--help)
usage
exit
;;
-s|--signoff)
with_signoff=true
shift
;;
--)
shift
break
;;
esac
done
if [[ -z ${1} ]]; then
usage
exit 1
fi
# get top
top=`git log --oneline HEAD^..HEAD | head -n1`
ctop=`echo ${top} | cut -d' ' -f1`
dtop=`echo ${top} | cut -d' ' -f2-`
l="$ctop $dtop"
if [ "$l" != "$top" ] ; then
echo "Reconstructed top failure"
echo $top
echo $l
exit 5
fi
# get list of commits and descriptions
old_IFS=${IFS}
IFS=$'\n'
j=0
for i in `grep -v '^#' $1`; do
c[${j}]=`echo ${i} | cut -d' ' -f1`
d[${j}]=`echo ${i} | cut -d' ' -f2-`
l="${c[${j}]} ${d[${j}]}"
if [ $l != $i ] ; then
echo "Reconstructed changeset failure $i"
exit 5
fi
((j+=1))
done
last=$((j - 1))
IFS=${old_IFS}
# skip over patches that are applied (checking description only)
match=0
for i in `seq 0 $last`; do
ct=${c[${i}]}
dt=${d[${i}]}
if [ "${dt}" == "${dtop}" ]; then
echo "Match found at $i: $dt"
match=$(($i + 1))
break;
fi
# echo "$i: $ct $dt"
done
for i in `seq $match $last`; do
ct=${c[${i}]}
dt=${d[${i}]}
echo "cherry-picking: $i: $ct $dt"
if $with_signoff; then
git cherry-pick --signoff $ct
else
git cherry-pick $ct
fi
if [ $? -ne 0 ] ; then
exit 5;
fi
done