From 5efef86cfa3ce88224edb68b2aa502dbf8939264 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 3 Nov 2021 07:02:21 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Update=20git=20helper=20scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buildroot/share/git/mffp | 14 +++++++++----- buildroot/share/git/mfinfo | 28 ++++++++++++++++------------ buildroot/share/git/mfnew | 6 +++--- buildroot/share/git/mfpr | 6 +++--- buildroot/share/git/mfqp | 4 ++-- buildroot/share/git/mfrb | 4 ++-- 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/buildroot/share/git/mffp b/buildroot/share/git/mffp index 2663a4a137..0680b3dba5 100755 --- a/buildroot/share/git/mffp +++ b/buildroot/share/git/mffp @@ -1,19 +1,23 @@ #!/usr/bin/env bash # -# mffp [1|2|3] [commit-id] +# mffp [1|2] [ref] # # Push the given commit (or HEAD) upstream immediately. -# By default: `git push upstream HEAD:bugfix-1.1.x` +# By default: `git push upstream HEAD:bugfix-2.0.x` # -[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` [1|2|3] [commit-id]" 1>&2 ; exit 1; } +usage() { echo "usage: `basename $0` [1|2] [ref]" 1>&2 } -if [[ $1 == '1' || $1 == '2' || $1 == '3' ]]; then +[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { usage ; exit 1; } + +if [[ $1 == '1' || $1 == '2' ]]; then MFINFO=$(mfinfo "$1") || exit 1 REF=${2:-HEAD} -else +elif [[ $# == 1 ]]; then MFINFO=$(mfinfo) || exit 1 REF=${1:-HEAD} +else + usage fi IFS=' ' read -a INFO <<< "$MFINFO" diff --git a/buildroot/share/git/mfinfo b/buildroot/share/git/mfinfo index 0f5d79a002..0c2113d922 100755 --- a/buildroot/share/git/mfinfo +++ b/buildroot/share/git/mfinfo @@ -2,15 +2,19 @@ # # mfinfo # -# Provide the following info about the working directory: +# Print the following info about the working copy: # # - Remote (upstream) Org name (MarlinFirmware) # - Remote (origin) Org name (your Github username) # - Repo Name (Marlin, MarlinDocumentation) -# - PR Target branch (bugfix-1.1.x, bugfix-2.0.x, dev-2.1.x, etc.) +# - PR Target branch (e.g., bugfix-2.0.x) # - Branch Arg (the branch argument or current branch) # - Current Branch # +# Example output +# > mfinfo -q ongoing +# MarlinFirmware john.doe Marlin bugfix-2.0.x ongoing bugfix-2.0.x -q +# CURR=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g') [[ -z $CURR ]] && { echo "No git repository here!" 1>&2 ; exit 1; } @@ -26,37 +30,37 @@ FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/') # Defaults if no arguments given BRANCH=$CURR -INDEX=1 +MORE="" +INDEX=2 +# Loop through arguments while [[ $# -gt 0 ]]; do + # Get an arg and maybe a val to go with it opt="$1" ; shift ; val="$1" + # Split up an arg containing = IFS='=' read -a PARTS <<<"$opt" [[ "${PARTS[1]}" != "" ]] && { EQUALS=1 ; opt="${PARTS[0]}" ; val="${PARTS[1]}" ; } - GOODVAL=1 if [[ "$val" =~ ^-{1,2}.* || ! "$opt" =~ ^-{1,2}.* ]]; then - GOODVAL=0 val="" fi case "$opt" in - -*|--*) MORE="$MORE$opt " ; [[ $EQUALS == 1 ]] && MORE="$MORE=$val" ;; - 1|2|3) INDEX=$opt ;; + -*|--*) MORE=" $MORE$opt" ; ((EQUALS)) && MORE="$MORE=$val" ;; + 1|2) INDEX=$opt ;; *) BRANCH="$opt" ;; esac done case "$REPO" in - Marlin ) TARG=bugfix-2.0.x ; [[ $INDEX == 1 ]] && TARG=bugfix-1.1.x ; [[ $INDEX == 3 ]] && TARG=dev-2.1.x ;; + Marlin ) TARG=bugfix-2.0.x ; ((INDEX == 1)) && TARG=bugfix-1.1.x ; [[ $BRANCH =~ ^[12]$ ]] && USAGE=1 ;; Configurations ) TARG=import-2.0.x ;; MarlinDocumentation ) TARG=master ;; AutoBuildMarlin ) TARG=master ;; esac -[[ $BRANCH =~ ^[123]$ ]] && USAGE=1 +[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1 ; } -[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2|3] [branch]" 1>&2 ; exit 1 ; } - -echo "$ORG $FORK $REPO $TARG $BRANCH $CURR $MORE" +echo "$ORG $FORK $REPO $TARG $BRANCH $CURR$MORE" diff --git a/buildroot/share/git/mfnew b/buildroot/share/git/mfnew index e491fea191..6d067a7f08 100755 --- a/buildroot/share/git/mfnew +++ b/buildroot/share/git/mfnew @@ -6,7 +6,7 @@ # usage() { - echo "usage: `basename $0` [1|2|3] [name]" 1>&2 + echo "usage: `basename $0` [1|2] [name]" 1>&2 } [[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { usage; exit 1; } @@ -19,12 +19,12 @@ BRANCH=pr_for_$TARG-$(date +"%G-%m-%d_%H.%M.%S") # BRANCH can be given as the last argument case "$#" in 1 ) case "$1" in - 1|2|3) ;; + 1|2) ;; *) BRANCH=$1 ;; esac ;; 2 ) case "$1" in - 1|2|3) BRANCH=$2 ;; + 1|2) BRANCH=$2 ;; *) usage ; exit 1 ;; esac ;; diff --git a/buildroot/share/git/mfpr b/buildroot/share/git/mfpr index b853c6929e..230bd2886c 100755 --- a/buildroot/share/git/mfpr +++ b/buildroot/share/git/mfpr @@ -1,11 +1,11 @@ #!/usr/bin/env bash # -# mfpr [1|2|3] +# mfpr [1|2] # -# Make a PR against bugfix-1.1.x or bugfix-2.0.x +# Make a PR targeted to MarlinFirmware/[repo] # -[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` [1|2|3] [branch]" 1>&2 ; exit 1; } +[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; } MFINFO=$(mfinfo "$@") || exit 1 IFS=' ' read -a INFO <<< "$MFINFO" diff --git a/buildroot/share/git/mfqp b/buildroot/share/git/mfqp index f0c4446a21..6e36e6113a 100755 --- a/buildroot/share/git/mfqp +++ b/buildroot/share/git/mfqp @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# mfqp [1|2|3] +# mfqp [1|2] # # - git add . # - git commit --amend @@ -24,7 +24,7 @@ while [ $IND -lt ${#INFO[@]} ]; do let IND+=1 done -[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2|3]" 1>&2 ; exit 1 ; } +[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2]" 1>&2 ; exit 1 ; } [[ $FORCE != 1 && $CURR == $TARG && $REPO != "MarlinDocumentation" ]] && { echo "Don't alter the PR Target branch."; exit 1 ; } diff --git a/buildroot/share/git/mfrb b/buildroot/share/git/mfrb index 071b0b3d59..b55a34e010 100755 --- a/buildroot/share/git/mfrb +++ b/buildroot/share/git/mfrb @@ -2,7 +2,7 @@ # # mfrb # -# Do "git rebase -i" against the "target" branch (bugfix-1.1.x, bugfix-2.0.x, dev-2.1.x, or master) +# Do "git rebase -i" against the repo's "target" branch # MFINFO=$(mfinfo "$@") || exit 1 @@ -21,7 +21,7 @@ while [ $IND -lt ${#INFO[@]} ]; do let IND+=1 done -[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2|3]" 1>&2 ; exit 1 ; } +[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2]" 1>&2 ; exit 1 ; } [[ $QUICK ]] || git fetch upstream git rebase upstream/$TARG && git rebase -i upstream/$TARG