You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
Plaintext
49 lines
1.1 KiB
Plaintext
9 years ago
|
#!/usr/bin/env bash
|
||
|
#
|
||
|
# mfup
|
||
|
#
|
||
7 years ago
|
# - Fetch latest upstream and replace the PR Target branch with
|
||
7 years ago
|
# - Rebase the (current or specified) branch on the PR Target
|
||
|
# - Force-push the branch to 'origin'
|
||
9 years ago
|
#
|
||
|
|
||
6 years ago
|
[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; }
|
||
9 years ago
|
|
||
7 years ago
|
MFINFO=$(mfinfo "$@") || exit 1
|
||
9 years ago
|
IFS=' ' read -a INFO <<< "$MFINFO"
|
||
|
ORG=${INFO[0]}
|
||
|
FORK=${INFO[1]}
|
||
|
REPO=${INFO[2]}
|
||
|
TARG=${INFO[3]}
|
||
7 years ago
|
BRANCH=${INFO[4]}
|
||
7 years ago
|
CURR=${INFO[5]}
|
||
9 years ago
|
|
||
|
set -e
|
||
|
|
||
7 years ago
|
# Prevent accidental loss of current changes
|
||
|
[[ $(git stash) != "No local "* ]] && HAS_STASH=1
|
||
|
|
||
9 years ago
|
echo "Fetching upstream ($ORG/$REPO)..."
|
||
|
git fetch upstream
|
||
|
|
||
|
if [[ $BRANCH != $TARG ]]; then
|
||
|
echo ; echo "Rebasing $BRANCH on $TARG..."
|
||
7 years ago
|
if [[ $BRANCH == $CURR ]] || git checkout $BRANCH; then
|
||
|
if git rebase upstream/$TARG; then
|
||
7 years ago
|
git push -f
|
||
9 years ago
|
else
|
||
7 years ago
|
echo "Looks like merge conflicts. Stopping here."
|
||
|
exit
|
||
9 years ago
|
fi
|
||
|
else
|
||
7 years ago
|
echo "No such branch!"
|
||
9 years ago
|
fi
|
||
7 years ago
|
else
|
||
|
git reset --hard upstream/$TARG
|
||
9 years ago
|
fi
|
||
7 years ago
|
|
||
|
echo
|
||
7 years ago
|
[[ $BRANCH != $CURR ]] && git checkout $CURR
|
||
7 years ago
|
|
||
|
[[ $HAS_STASH == 1 ]] && git stash pop
|