forked from cmccabe/cmccabe-hbin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-cherry-pick-all.sh
executable file
·62 lines (55 loc) · 1.31 KB
/
git-cherry-pick-all.sh
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
#!/usr/bin/env bash
die() {
echo $@
exit 1
}
usage() {
cat <<EOF
git-cherry-pick-all.sh: cherry-pick a patch to multiple branches.
-c <commit>: the commit to cherry-pick
-h: this help message
-i: interactive mode
-x: use -x flag in git cherry-pick
EOF
}
yesno() {
args=$1
RESULT=2
while [ $RESULT -eq 2 ]; do
read -p "$args" choice
case "$choice" in
y|Y) RESULT=1;;
n|N) RESULT=0;;
*) echo "invalid; please enter y or n";;
esac
done
}
[ $# -lt 1 ] && die "you must specify the remote to pull from"
remote=$1
commit=""
flags=""
interactive=0
while getopts "c:hix" flag; do
case $flag in
c) commit=$OPTARG;;
h) usage; exit 0;;
i) interactive=1;;
x) flags="$flags -x";;
*) usage; exit 1;;
esac
#echo "$flag" $OPTIND $OPTARG
done
[ x"$commit" == "x" ] && die "you must specify a commit with -c"
git branch | sed 's/\*//' > /tmp/$$
exec 4< /tmp/$$
while read branch <&4; do
RESULT=1
if [ $interactive -eq 1 ]; then
yesno "would you like to cherry-pick to $branch? "
fi
if [ $RESULT -eq 1 ]; then
git checkout $branch || die "failed to checkout $branch"
git cherry-pick $flags $commit || die "failed to cherry-pick"
fi
done
rm -f /tmp/$$