Update Marlin+Github helper scripts

This commit is contained in:
Scott Lahteine 2017-07-02 20:43:57 -05:00
parent 015839fc50
commit ab79933d1f
12 changed files with 94 additions and 93 deletions

View file

@ -6,11 +6,13 @@
# commit log to watch Travis CI progress. # commit log to watch Travis CI progress.
# #
MFINFO=$(mfinfo) || exit [[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
MFINFO=$(mfinfo) || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
FORK=${INFO[1]} FORK=${INFO[1]}
REPO=${INFO[2]} REPO=${INFO[2]}
BRANCH=${INFO[4]} BRANCH=${INFO[5]}
git push --set-upstream origin $BRANCH git push --set-upstream origin $BRANCH

View file

@ -5,20 +5,16 @@
# Add a remote and fetch it # Add a remote and fetch it
# #
MFINFO=$(mfinfo) || exit [[ $# == 1 ]] || { echo "Usage: `basename $0` user" 1>&2 ; exit 1; }
USER=$1
MFINFO=$(mfinfo) || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
REPO=${INFO[2]} REPO=${INFO[2]}
OLDBRANCH=${INFO[4]}
case "$#" in
1 ) USER=$1 ;;
* ) echo "Usage: `basename $0` [user]" 1>&2 ; exit 1 ;;
esac
set -e set -e
echo "Adding and fetching $USER..." echo "Adding and fetching $USER..."
git remote add "$USER" "git@github.com:$USER/$REPO.git"
git remote add -f "$USER" "git@github.com:$USER/$REPO.git" git fetch "$USER"

View file

@ -21,9 +21,10 @@ echo "Pruning Remotely-deleted Branches..."
git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D
echo echo
# List fork branches that don't match local branches
echo "You may want to remove (or checkout) these refs..." echo "You may want to remove (or checkout) these refs..."
comm -23 \ comm -23 \
<(git branch --all | sed 's/^[\* ] //' | grep origin/ | grep -v "\->" | awk '{ print $1; }' | sed 's/remotes\/origin\///') \ <(git branch --all | sed 's/^[\* ] //' | grep origin/ | grep -v "\->" | awk '{ print $1; }' | sed 's/remotes\/origin\///') \
<(git branch --all | sed 's/^[\* ] //' | grep -v remotes/ | awk '{ print $1; }') \ <(git branch --all | sed 's/^[\* ] //' | grep -v remotes/ | awk '{ print $1; }') \
| awk '{ print "git branch -d -r origin/" $1; print "git checkout origin/" $1 " -b " $1; }' | awk '{ print "git branch -d -r origin/" $1; print "git checkout origin/" $1 " -b " $1; print ""; }'
echo echo

View file

@ -5,16 +5,15 @@
# Start Jekyll in watch mode to work on Marlin Documentation and preview locally # Start Jekyll in watch mode to work on Marlin Documentation and preview locally
# #
MFINFO=$(mfinfo "$@") || exit [[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
ORG=${INFO[0]} ORG=${INFO[0]}
REPO=${INFO[2]} REPO=${INFO[2]}
BRANCH=${INFO[4]} BRANCH=${INFO[5]}
if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then [[ $ORG == "MarlinFirmware" && $REPO == "MarlinDocumentation" ]] || { echo "Wrong repository." 1>&2; exit 1; }
echo "Wrong repository."
exit
fi
opensite() { opensite() {
TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }') TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')

View file

@ -2,27 +2,25 @@
# #
# mfinfo # mfinfo
# #
# Get the following helpful git info about the working directory: # Provide the following info about the working directory:
# #
# - 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 or MarlinDev) # - Repo Name (Marlin, MarlinDev, MarlinDocumentation)
# - Marlin Target branch (RCBugFix or dev) # - PR Target branch (bugfix-1.1.x, dev, or master)
# - Branch Name (the current branch or the one that was passed) # - Branch Arg (the branch argument or current branch)
# - Current Branch
# #
REPO=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*\/(.*)\.git/\1/') CURR=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g')
[[ -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; }
if [[ -z $REPO ]]; then REPO=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*\/(.*)\.git/\1/')
echo "`basename $0`: No 'upstream' remote found." 1>&2 ; exit 1 [[ -z $REPO ]] && { echo "`basename $0`: No 'upstream' remote found. (Did you run mfinit?)" 1>&2 ; exit 1; }
fi
ORG=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/') 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; }
if [[ $ORG != MarlinFirmware ]]; then
echo "`basename $0`: Not a Marlin repository."
exit 1
fi
case "$REPO" in case "$REPO" in
Marlin ) TARG=bugfix-1.1.x ;; Marlin ) TARG=bugfix-1.1.x ;;
@ -33,13 +31,9 @@ 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/')
case "$#" in case "$#" in
0 ) BRANCH=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g') ;; 0 ) BRANCH=$CURR ;;
1 ) BRANCH=$1 ;; 1 ) BRANCH=$1 ;;
* ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;; * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
esac esac
if [[ $BRANCH == "(no" ]]; then echo "$ORG $FORK $REPO $TARG $BRANCH $CURR"
echo "Git is busy with merge, rebase, etc." 1>&2 ; exit 1
fi
echo "$ORG $FORK $REPO $TARG $BRANCH"

View file

@ -5,12 +5,13 @@
# Create the upstream remote for a forked repository # Create the upstream remote for a forked repository
# #
[[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
[[ -z $(git branch 2>/dev/null | grep ^* | sed 's/\* //g') ]] && { echo "No git repository here!" 1>&2 ; exit 1; }
REPO=$(git remote get-url origin 2>/dev/null | sed -E 's/.*\/(.*)\.git/\1/') REPO=$(git remote get-url origin 2>/dev/null | sed -E 's/.*\/(.*)\.git/\1/')
[[ -z $REPO ]] && { echo "`basename $0`: No 'origin' remote found." 1>&2 ; exit 1; }
if [[ -z $REPO ]]; then echo "Adding 'upstream' remote for convenience."
echo "`basename $0`: No 'origin' remote found." 1>&2 ; exit 1
fi
git remote add upstream "git@github.com:MarlinFirmware/$REPO.git" git remote add upstream "git@github.com:MarlinFirmware/$REPO.git"
git fetch upstream git fetch upstream

View file

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

View file

@ -5,22 +5,22 @@
# Make a PR of the current branch against RCBugFix or dev # Make a PR of the current branch against RCBugFix or dev
# #
MFINFO=$(mfinfo "$@") || exit [[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
ORG=${INFO[0]} ORG=${INFO[0]}
FORK=${INFO[1]} FORK=${INFO[1]}
REPO=${INFO[2]} REPO=${INFO[2]}
TARG=${INFO[3]} TARG=${INFO[3]}
BRANCH=${INFO[4]} BRANCH=${INFO[4]}
OLDBRANCH=${INFO[5]}
if [[ ! -z "$1" ]]; then { BRANCH=$1 ; git checkout $1 || exit 1; } fi [[ $BRANCH == $TARG ]] && { echo "Can't create a PR from the PR Target ($BRANCH). Make a copy first." 1>&2 ; exit 1; }
if [[ $BRANCH == $TARG ]]; then [[ $BRANCH != $OLDBRANCH ]] && { git checkout $BRANCH || exit 1; }
echo "Can't make a PR from $BRANCH" ; exit
fi
# See if it's been pushed yet
if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }') TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
@ -33,3 +33,5 @@ else
echo "Opening a New PR Form..." echo "Opening a New PR Form..."
"$TOOL" "$URL" "$TOOL" "$URL"
fi fi
[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH

View file

@ -9,7 +9,9 @@
# any permanent changes to 'master'. # any permanent changes to 'master'.
# #
MFINFO=$(mfinfo "$@") || exit [[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
ORG=${INFO[0]} ORG=${INFO[0]}
FORK=${INFO[1]} FORK=${INFO[1]}

View file

@ -5,26 +5,22 @@
# 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`
# #
MFINFO=$(mfinfo) || exit [[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
MFINFO=$(mfinfo) || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
REPO=${INFO[2]}
TARG=${INFO[3]}
BRANCH=${INFO[5]}
if [[ ${INFO[4]} == "(no" ]]; then git add .
echo "Branch is unavailable!" ; exit 1
fi
case "$#" in
0 ) ;;
* ) echo "Usage: `basename $0`" 1>&2 ; exit 1 ;;
esac
git add * .travis.yml
git commit -m "patch" git commit -m "patch"
if [[ ${INFO[3]} == ${INFO[4]} ]]; then if [[ $BRANCH == $TARG ]]; then
if [[ ${INFO[2]} == "MarlinDocumentation" ]]; then if [[ $REPO == "MarlinDocumentation" ]]; then
git rebase -i HEAD~2 git rebase -i HEAD~2
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

View file

@ -5,16 +5,15 @@
# Do "git rebase -i" against the "target" branch (RCBugFix or dev) # Do "git rebase -i" against the "target" branch (RCBugFix or dev)
# #
MFINFO=$(mfinfo) || exit [[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
IFS=' ' read -a INFO <<< "$MFINFO"
case "$#" in MFINFO=$(mfinfo) || exit 1
0 ) ;; IFS=' ' read -a INFO <<< "$MFINFO"
* ) echo "Usage: `basename $0`" 1>&2 ; exit 1 ;; TARG=${INFO[3]}
esac BRANCH=${INFO[5]}
# If the branch isn't currently the PR target # If the branch isn't currently the PR target
if [[ ${INFO[3]} != ${INFO[4]} ]]; then if [[ $TARG != $BRANCH ]]; then
git fetch upstream git fetch upstream
git rebase upstream/${INFO[3]} && git rebase -i upstream/${INFO[3]} git rebase upstream/$TARG && git rebase -i upstream/$TARG
fi fi

View file

@ -2,47 +2,55 @@
# #
# mfup # mfup
# #
# Fetch and merge upstream changes, optionally with a branch # - 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'
# -
# #
MFINFO=$(mfinfo) || exit [[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO" IFS=' ' read -a INFO <<< "$MFINFO"
ORG=${INFO[0]} ORG=${INFO[0]}
FORK=${INFO[1]} FORK=${INFO[1]}
REPO=${INFO[2]} REPO=${INFO[2]}
TARG=${INFO[3]} TARG=${INFO[3]}
OLDBRANCH=${INFO[4]} BRANCH=${INFO[4]}
OLDBRANCH=${INFO[5]}
case "$#" in
0 ) BRANCH=$OLDBRANCH ;;
1 ) BRANCH=$1 ;;
* ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
esac
set -e set -e
# Prevent accidental loss of current changes
[[ $(git stash) != "No local "* ]] && HAS_STASH=1
echo "Fetching upstream ($ORG/$REPO)..." echo "Fetching upstream ($ORG/$REPO)..."
git fetch upstream git fetch upstream
echo ; echo "Bringing $TARG up to date..." echo ; echo "Bringing $TARG up to date..."
git checkout -q $TARG || git branch checkout upstream/$TARG -b $TARG && git push --set-upstream origin $TARG if [[ git checkout -q $TARG ]]; then
git merge upstream/$TARG git reset --hard upstream/$TARG
git push origin 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 git checkout $BRANCH; then
echo echo
if git rebase $TARG; then if git rebase $TARG; then
git push -f ; echo git push -f
[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
else else
echo "Looks like merge conflicts. Stopping here." echo "Looks like merge conflicts. Stopping here." ; exit
fi fi
else else
echo "No such branch!" ; echo echo "No such branch!"
git checkout $OLDBRANCH
fi fi
fi fi
echo
[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
[[ $HAS_STASH == 1 ]] && git stash pop