aboutsummaryrefslogtreecommitdiff
path: root/buildroot/share/git/mfup
diff options
context:
space:
mode:
authorGeorgiy Bondarenko <69736697+nehilo@users.noreply.github.com>2021-03-04 20:54:23 +0300
committerGeorgiy Bondarenko <69736697+nehilo@users.noreply.github.com>2021-03-04 20:54:23 +0300
commite8701195e66f2d27ffe17fb514eae8173795aaf7 (patch)
tree9f519c4abf6556b9ae7190a6210d87ead1dfadde /buildroot/share/git/mfup
downloadkp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.tar.xz
kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.zip
Initial commit
Diffstat (limited to 'buildroot/share/git/mfup')
-rw-r--r--buildroot/share/git/mfup48
1 files changed, 48 insertions, 0 deletions
diff --git a/buildroot/share/git/mfup b/buildroot/share/git/mfup
new file mode 100644
index 0000000..691259e
--- /dev/null
+++ b/buildroot/share/git/mfup
@@ -0,0 +1,48 @@
+#!/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 1
+IFS=' ' 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=1
+
+echo "Fetching upstream ($ORG/$REPO)..."
+git fetch upstream
+
+if [[ $BRANCH != $TARG ]]; then
+ echo ; echo "Rebasing $BRANCH on $TARG..."
+ if [[ $BRANCH == $CURR ]] || git checkout $BRANCH; then
+ if git rebase upstream/$TARG; then
+ git push -f
+ else
+ echo "Looks like merge conflicts. Stopping here."
+ exit
+ fi
+ else
+ echo "No such branch!"
+ fi
+else
+ git reset --hard upstream/$TARG
+fi
+
+echo
+[[ $BRANCH != $CURR ]] && git checkout $CURR
+
+[[ $HAS_STASH == 1 ]] && git stash pop