forked from lzap/bin-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-xcp
executable file
·51 lines (45 loc) · 1.69 KB
/
git-xcp
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
#!/bin/bash
[[ -d .git ]] || (echo "Not a git repo, fool!" && exit 1)
TO_BRANCHES=$(cat .git/xcp-to-branch 2>/dev/null)
FROM_BRANCH=$(cat .git/xcp-from-branch 2>/dev/null)
set -e
echo "Looks like you want to cherry-pick, huh?!"
function cleanup() {
if [ -n "$1" ]; then
echo "ABORTED by $1"
elif [ $status -ne 0 ]; then
echo "FAILURE (status $status)"
else
echo "SUCCESS, to drop a github comment:"
echo "---"
echo "Commit(s) $COMMITS were cherry-picked into: $TO_BRANCHES"
for TO_BRANCH in $TO_BRANCHES; do
git log --pretty="format:* %h %s" $TO_BRANCH...$TO_BRANCH~1
done
echo "---"
fi
git stash pop &>/dev/null || true
}
git stash &>/dev/null || true
trap 'status=$?; cleanup; exit $status' EXIT
trap 'trap - HUP; cleanup SIGHUP; kill -HUP $$' HUP
trap 'trap - INT; cleanup SIGINT; kill -INT $$' INT
trap 'trap - TERM; cleanup SIGTERM; kill -TERM $$' TERM
read -e -i "$TO_BRANCHES" -p "Space-separated branches you want to pick INTO: " TO_BRANCHES
[[ -z "$TO_BRANCHES" ]] && (echo "You gotta be kidding me, we're done." && exit 1)
echo "$TO_BRANCHES" > .git/xcp-to-branch
read -e -i "$FROM_BRANCH" -p "Branch you want to pick FROM: " FROM_BRANCH
[[ -z "$FROM_BRANCH" ]] && (echo "You gotta be kidding me, we're done." && exit 1)
echo "$FROM_BRANCH" > .git/xcp-from-branch
git checkout "$FROM_BRANCH"
git pull
echo "Allright, allright, here is the menu:"
git log --pretty="format:%h %s" HEAD...HEAD~10
echo -n "Commits separated by space or enter to give up: "
read COMMITS
[[ -z "$COMMITS" ]] && exit 1
for TO_BRANCH in $TO_BRANCHES; do
git checkout "$TO_BRANCH"
git pull
git cherry-pick -x $COMMITS && echo "Hit ENTER to *PUSH* into $TO_BRANCH, Ctrl-C to interrupt." && read && git push
done