Add 'ghpc' helper script
This commit is contained in:
parent
32afe1d102
commit
6d92a0a33b
2 changed files with 73 additions and 4 deletions
|
@ -18,7 +18,7 @@ The following scripts can be used on any system with a GNU environment to speed
|
|||
|
||||
File|Description
|
||||
----|-----------
|
||||
mfadd [user]|Add and Fetch Remote - Add another Github user's fork of Marlin as a remote, then fetch it. Optionally, check out one of their branches.
|
||||
mfadd [user]|Add and Fetch Remote - Add and fetch another user's Marlin fork. Optionally, check out one of their branches.
|
||||
mfinit|Init Working Copy - Create a remote named '`upstream`' (for use by the other scripts) pointing to the '`MarlinFirmware`' fork. This only needs to be used once. Newer versions of Github Desktop may create `upstream` on your behalf.
|
||||
|
||||
#### Branches
|
||||
|
@ -41,14 +41,15 @@ mfqp|Quick Patch - Commit all current changes as "patch", then do `mfrb`, follow
|
|||
|
||||
File|Description
|
||||
----|-----------
|
||||
mfdoc|Build the documentation and preview it locally.
|
||||
mfpub|Build the documentation and publish it to marlinfw.org via Github.
|
||||
mfdoc|Build the documentation with Jekyll and preview it locally.
|
||||
mfpub|Build and publish the documentation to marlinfw.org.
|
||||
|
||||
#### Utilities
|
||||
|
||||
File|Description
|
||||
----|-----------
|
||||
ghtp -[h/s]|Set the protocol to use for all remotes. -h for HTTPS, -s for SSL.
|
||||
ghpc [-f]|Push current branch to 'origin' or to the remote indicated by the error.
|
||||
mfinfo|This utility script is used by the other scripts to get:<br/>- The upstream project ('`MarlinFirmware`')<br/>- the '`origin`' project (i.e., your Github username),<br/>- the repository name ('`Marlin`'),<br/>- the PR target branch ('`bugfix-1.1.x`'), and<br/>- the current branch (or the first command-line argument).<br/><br/>By itself, `mfinfo` simply prints these values to the console.
|
||||
mfclean |Prune your merged and remotely-deleted branches.
|
||||
|
||||
|
@ -56,4 +57,4 @@ mfclean |Prune your merged and remotely-deleted bra
|
|||
|
||||
### Examples
|
||||
|
||||
Coming Soon!
|
||||
For a demonstration of these scripts see the video [Marlin Live - May 9 2019](https://youtu.be/rwT4G0uVTIY). There is also an old write-up at [#3193](https://github.com/MarlinFirmware/Marlin/issues/3193).
|
||||
|
|
68
buildroot/share/git/ghpc
Executable file
68
buildroot/share/git/ghpc
Executable file
|
@ -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."
|
Reference in a new issue