Blame | Last modification | View Log | RSS feed
#!/usr/bin/env bash## mfup## - 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'#[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; }MFINFO=$(mfinfo "$@") || exit 1IFS=' ' read -a INFO <<< "$MFINFO"ORG=${INFO[0]}FORK=${INFO[1]}REPO=${INFO[2]}TARG=${INFO[3]}BRANCH=${INFO[4]}CURR=${INFO[5]}set -e# Prevent accidental loss of current changes[[ $(git stash) != "No local "* ]] && HAS_STASH=1echo "Fetching upstream ($ORG/$REPO)..."git fetch upstreamif [[ $BRANCH != $TARG ]]; thenecho ; echo "Rebasing $BRANCH on $TARG..."if [[ $BRANCH == $CURR ]] || git checkout $BRANCH; thenif git rebase upstream/$TARG; thengit push -felseecho "Looks like merge conflicts. Stopping here."exitfielseecho "No such branch!"fielsegit reset --hard upstream/$TARGfiecho[[ $BRANCH != $CURR ]] && git checkout $CURR[[ $HAS_STASH == 1 ]] && git stash pop