-
Notifications
You must be signed in to change notification settings - Fork 5
/
cherry_pick.sh
executable file
·43 lines (36 loc) · 1.13 KB
/
cherry_pick.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
#!/usr/bin/bash
#
# Small helper script to cherry-pick a specific file
# to the stripped branch.
# This will take the most recent commit where <file>
# was edited, and cherry pick that to the stripped branch.
#
if [ $# -eq 0 ]; then
echo "Please supply one or more file name(s) for cherry-picking"
echo "them to the stripped branch"
exit 1
fi
branch=stripped
# Ensure we are on main, this should probably
# not be there.
git checkout main
declare -a lines=($(git log --reverse --oneline --no-abbrev-commit -- $@ | awk '{print $1}'))
git checkout $branch
for hash in ${lines[@]}
do
# Check if the commit has already been cherry-picked
# to branch.
# We search the commit log for the hash name.
# In case users forget -x, this probably won't work.
out=$(git log --oneline --grep=$hash $branch)
# If there is no cherry-pick of the commit, the log command
# will return an empty string. Hence we test the length of the
# variable.
if [ ${#out} -le 1 ]; then
# We can't find it, so we should cherry-pick it ;)
git cherry-pick -x $hash
else
echo "$hash already cherry-picked by: $out"
fi
done
git checkout main