From e8701195e66f2d27ffe17fb514eae8173795aaf7 Mon Sep 17 00:00:00 2001 From: Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> Date: Thu, 4 Mar 2021 22:54:23 +0500 Subject: Initial commit --- buildroot/share/git/ghpc | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 buildroot/share/git/ghpc (limited to 'buildroot/share/git/ghpc') diff --git a/buildroot/share/git/ghpc b/buildroot/share/git/ghpc new file mode 100644 index 0000000..a3def15 --- /dev/null +++ b/buildroot/share/git/ghpc @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# +# ghpc (GitHub Push Current) +# +# - Push current branch to its remote. Try the following until it works: +# - Plain 'git push' +# - 'git push -f' +# - Try the 'git push' command from the 'git push' error message +# - Try adding '-f' to that command +# + +yay() { echo "SUCCESS" ; } +boo() { echo "FAIL" ; } + +FORCE=$([[ "$1" == "--force" || "$1" == "-f" ]] && echo 1) + +if [[ ! $FORCE ]]; then + echo -n "trying 'git push' ...... " + git push >/dev/null 2>&1 && { yay ; exit ; } + boo +fi + +echo -n "trying 'git push -f' ... " + +# Get the error output from the failed push +# and get the recommended 'git push' line +git push -f 2>&1 | { + CMD="" + + ltrim() { + [[ "$1" =~ [^[:space:]].* ]] + printf "%s" "$BASH_REMATCH" + } + + while IFS= read -r line + do + #echo "$line" + if [[ -z "$CMD" && $line =~ "git push" ]]; then + CMD=$(ltrim "$line") + fi + done + + # if a command was found try it + if [[ -n "$CMD" ]]; then + + boo + + if [[ ! $FORCE ]]; then + echo -n "trying '$CMD' ...... " + $CMD >/dev/null 2>&1 && { yay ; exit ; } + boo + fi + + fCMD=${CMD/ push / push -f } + echo -n "trying '$fCMD' ... " + $fCMD >/dev/null 2>&1 && { yay ; exit ; } + boo + + exit 1 + + else + + yay + + fi +} + +[[ ${PIPESTATUS[1]} == 1 ]] && echo "Sorry! Failed to push current branch." -- cgit v1.2.3