Update git helper scripts

This commit is contained in:
Scott Lahteine 2017-11-04 17:33:00 -05:00
parent e0a6ee8da5
commit ca21367dde
5 changed files with 57 additions and 38 deletions

View file

@ -7,11 +7,15 @@
# - Remote (upstream) Org name (MarlinFirmware) # - Remote (upstream) Org name (MarlinFirmware)
# - Remote (origin) Org name (your Github username) # - Remote (origin) Org name (your Github username)
# - Repo Name (Marlin, MarlinDev, MarlinDocumentation) # - Repo Name (Marlin, MarlinDev, MarlinDocumentation)
# - PR Target branch (bugfix-2.0.x, dev, or master) # - PR Target branch (bugfix-1.1.x, bugfix-2.0.x, or master)
# - Branch Arg (the branch argument or current branch) # - Branch Arg (the branch argument or current branch)
# - Current Branch # - Current Branch
# #
usage() {
echo "Usage: `basename $0` [1|2] [branch]" 1>&2
}
CURR=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g') CURR=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g')
[[ -z $CURR ]] && { echo "No git repository here!" 1>&2 ; exit 1; } [[ -z $CURR ]] && { echo "No git repository here!" 1>&2 ; exit 1; }
[[ $CURR == "(no"* ]] && { echo "Git is busy with merge, rebase, etc." 1>&2 ; exit 1; } [[ $CURR == "(no"* ]] && { echo "Git is busy with merge, rebase, etc." 1>&2 ; exit 1; }
@ -23,17 +27,29 @@ ORG=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
[[ $ORG == MarlinFirmware ]] || { echo "`basename $0`: Not a Marlin repository." 1>&2 ; exit 1; } [[ $ORG == MarlinFirmware ]] || { echo "`basename $0`: Not a Marlin repository." 1>&2 ; exit 1; }
case "$REPO" in case "$REPO" in
Marlin ) TARG=bugfix-2.0.x ;; Marlin ) TARG=bugfix-1.1.x ;
MarlinDev ) TARG=dev ;; [[ $# > 0 ]] && [[ $1 == 2 ]] && TARG=bugfix-2.0.x
;;
MarlinDocumentation ) TARG=master ;; MarlinDocumentation ) TARG=master ;;
esac esac
FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/') FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
# BRANCH can be given as the last argument
case "$#" in case "$#" in
0 ) BRANCH=$CURR ;; 0 ) BRANCH=$CURR ;;
1 ) BRANCH=$1 ;; 1 )
* ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;; case "$1" in
1|2) BRANCH=$CURR ;;
*) BRANCH=$1 ;;
esac
;;
2 )
case "$1" in
1|2) BRANCH=$2 ;;
*) usage ; exit 1 ;;
esac
;;
esac esac
echo "$ORG $FORK $REPO $TARG $BRANCH $CURR" echo "$ORG $FORK $REPO $TARG $BRANCH $CURR"

View file

@ -5,15 +5,29 @@
# Create a new branch from the default target with the given name # Create a new branch from the default target with the given name
# #
[[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; } usage() {
echo "Usage: `basename $0` [1|2] [name]" 1>&2
}
MFINFO=$(mfinfo) || exit 1 [[ $# < 3 ]] || { usage ; exit 1 ; }
MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
TARG=${INFO[3]} TARG=${INFO[3]}
BRANCH=pr_for_$TARG-$(date +"%G-%m-%d_%H.%M.%S")
# BRANCH can be given as the last argument
case "$#" in case "$#" in
0 ) BRANCH=pr_for_$TARG-$(date +"%G-%m-%d_%H.%M.%S") ;; 1 ) case "$1" in
1 ) BRANCH=$1 ;; 1|2) ;;
*) BRANCH=$1 ;;
esac
;;
2 ) case "$1" in
1|2) BRANCH=$2 ;;
*) usage ; exit 1 ;;
esac
;;
esac esac
git fetch upstream git fetch upstream

View file

@ -5,24 +5,23 @@
# Add all changed files, commit as "patch", do `mfrb` and `git push -f` # Add all changed files, commit as "patch", do `mfrb` and `git push -f`
# #
[[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; } [[ $# < 2 ]] || { echo "Usage: `basename $0` [1|2]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo) || exit 1 MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
REPO=${INFO[2]} REPO=${INFO[2]}
TARG=${INFO[3]} TARG=${INFO[3]}
BRANCH=${INFO[5]} CURR=${INFO[5]}
git add . git add .
git commit -m "patch" git commit -m "patch"
if [[ $BRANCH == $TARG ]]; then if [[ $CURR == $TARG ]]; then
if [[ $REPO == "MarlinDocumentation" ]]; then if [[ $REPO == "MarlinDocumentation" ]]; then
git rebase -i HEAD~2 git rebase -i HEAD~2 && git push -f
else else
echo "Don't alter the PR Target branch."; exit 1 echo "Don't alter the PR Target branch."; exit 1
fi fi
else else
mfrb mfrb "$@" && git push -f
git push -f
fi fi

View file

@ -2,18 +2,18 @@
# #
# mfrb # mfrb
# #
# Do "git rebase -i" against the "target" branch (RCBugFix or dev) # Do "git rebase -i" against the "target" branch (bugfix-1.1.x, bugfix-2.0.x, or master)
# #
[[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; } [[ $# < 2 ]] || { echo "Usage: `basename $0` [1|2]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo) || exit 1 MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
TARG=${INFO[3]} TARG=${INFO[3]}
BRANCH=${INFO[5]} CURR=${INFO[5]}
# If the branch isn't currently the PR target # If the branch isn't currently the PR target
if [[ $TARG != $BRANCH ]]; then if [[ $TARG != $CURR ]]; then
git fetch upstream git fetch upstream
git rebase upstream/$TARG && git rebase -i upstream/$TARG git rebase upstream/$TARG && git rebase -i upstream/$TARG
fi fi

View file

@ -5,10 +5,9 @@
# - Fetch latest upstream and replace the PR Target branch with # - Fetch latest upstream and replace the PR Target branch with
# - Rebase the (current or specified) branch on the PR Target # - Rebase the (current or specified) branch on the PR Target
# - Force-push the branch to 'origin' # - Force-push the branch to 'origin'
# -
# #
[[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; } [[ $# < 3 ]] || { echo "Usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo "$@") || exit 1 MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
@ -17,7 +16,7 @@ FORK=${INFO[1]}
REPO=${INFO[2]} REPO=${INFO[2]}
TARG=${INFO[3]} TARG=${INFO[3]}
BRANCH=${INFO[4]} BRANCH=${INFO[4]}
OLDBRANCH=${INFO[5]} CURR=${INFO[5]}
set -e set -e
@ -27,23 +26,14 @@ set -e
echo "Fetching upstream ($ORG/$REPO)..." echo "Fetching upstream ($ORG/$REPO)..."
git fetch upstream git fetch upstream
echo ; echo "Bringing $TARG up to date..."
if [[ ! $(git checkout -q $TARG) ]]; then
git reset --hard upstream/$TARG
git push -f origin
else
git checkout upstream/$TARG -b $TARG
git push --set-upstream origin $TARG
fi
if [[ $BRANCH != $TARG ]]; then if [[ $BRANCH != $TARG ]]; then
echo ; echo "Rebasing $BRANCH on $TARG..." echo ; echo "Rebasing $BRANCH on $TARG..."
if git checkout $BRANCH; then if [[ $BRANCH == $CURR ]] || git checkout $BRANCH; then
echo if git rebase upstream/$TARG; then
if git rebase $TARG; then
git push -f git push -f
else else
echo "Looks like merge conflicts. Stopping here." ; exit echo "Looks like merge conflicts. Stopping here."
exit
fi fi
else else
echo "No such branch!" echo "No such branch!"
@ -51,6 +41,6 @@ if [[ $BRANCH != $TARG ]]; then
fi fi
echo echo
[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH [[ $BRANCH != $CURR ]] && git checkout $CURR
[[ $HAS_STASH == 1 ]] && git stash pop [[ $HAS_STASH == 1 ]] && git stash pop