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