2016-04-19 04:18:35 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# mfup
|
|
|
|
#
|
2017-07-07 02:24:30 +00:00
|
|
|
# - Fetch latest upstream and replace the PR Target branch with
|
2017-07-03 01:43:57 +00:00
|
|
|
# - Rebase the (current or specified) branch on the PR Target
|
|
|
|
# - Force-push the branch to 'origin'
|
2016-04-19 04:18:35 +00:00
|
|
|
#
|
|
|
|
|
2018-03-02 02:41:01 +00:00
|
|
|
[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; }
|
2016-04-19 04:18:35 +00:00
|
|
|
|
2017-07-03 01:43:57 +00:00
|
|
|
MFINFO=$(mfinfo "$@") || exit 1
|
2016-04-19 04:18:35 +00:00
|
|
|
IFS=' ' read -a INFO <<< "$MFINFO"
|
|
|
|
ORG=${INFO[0]}
|
|
|
|
FORK=${INFO[1]}
|
|
|
|
REPO=${INFO[2]}
|
|
|
|
TARG=${INFO[3]}
|
2017-07-03 01:43:57 +00:00
|
|
|
BRANCH=${INFO[4]}
|
2017-11-04 22:33:00 +00:00
|
|
|
CURR=${INFO[5]}
|
2016-04-19 04:18:35 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2017-07-03 01:43:57 +00:00
|
|
|
# Prevent accidental loss of current changes
|
|
|
|
[[ $(git stash) != "No local "* ]] && HAS_STASH=1
|
|
|
|
|
2016-04-19 04:18:35 +00:00
|
|
|
echo "Fetching upstream ($ORG/$REPO)..."
|
|
|
|
git fetch upstream
|
|
|
|
|
|
|
|
if [[ $BRANCH != $TARG ]]; then
|
|
|
|
echo ; echo "Rebasing $BRANCH on $TARG..."
|
2017-11-04 22:33:00 +00:00
|
|
|
if [[ $BRANCH == $CURR ]] || git checkout $BRANCH; then
|
|
|
|
if git rebase upstream/$TARG; then
|
2017-07-03 01:43:57 +00:00
|
|
|
git push -f
|
2016-04-19 04:18:35 +00:00
|
|
|
else
|
2017-11-04 22:33:00 +00:00
|
|
|
echo "Looks like merge conflicts. Stopping here."
|
|
|
|
exit
|
2016-04-19 04:18:35 +00:00
|
|
|
fi
|
|
|
|
else
|
2017-07-03 01:43:57 +00:00
|
|
|
echo "No such branch!"
|
2016-04-19 04:18:35 +00:00
|
|
|
fi
|
2017-11-29 01:01:47 +00:00
|
|
|
else
|
|
|
|
git reset --hard upstream/$TARG
|
2016-04-19 04:18:35 +00:00
|
|
|
fi
|
2017-07-03 01:43:57 +00:00
|
|
|
|
|
|
|
echo
|
2017-11-04 22:33:00 +00:00
|
|
|
[[ $BRANCH != $CURR ]] && git checkout $CURR
|
2017-07-03 01:43:57 +00:00
|
|
|
|
|
|
|
[[ $HAS_STASH == 1 ]] && git stash pop
|