From ab79933d1fd2b4f761810f8911cb6abb14a1690c Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Sun, 2 Jul 2017 20:43:57 -0500
Subject: [PATCH 1/4] Update Marlin+Github helper scripts

---
 buildroot/share/git/firstpush |  6 +++--
 buildroot/share/git/mfadd     | 16 +++++--------
 buildroot/share/git/mfclean   |  3 ++-
 buildroot/share/git/mfdoc     | 11 ++++-----
 buildroot/share/git/mfinfo    | 32 +++++++++++--------------
 buildroot/share/git/mfinit    | 13 ++++++-----
 buildroot/share/git/mfnew     |  5 ++--
 buildroot/share/git/mfpr      | 14 ++++++-----
 buildroot/share/git/mfpub     |  4 +++-
 buildroot/share/git/mfqp      | 24 ++++++++-----------
 buildroot/share/git/mfrb      | 15 ++++++------
 buildroot/share/git/mfup      | 44 +++++++++++++++++++++--------------
 12 files changed, 94 insertions(+), 93 deletions(-)

diff --git a/buildroot/share/git/firstpush b/buildroot/share/git/firstpush
index 0d8e71c796..60767f04bc 100755
--- a/buildroot/share/git/firstpush
+++ b/buildroot/share/git/firstpush
@@ -6,11 +6,13 @@
 # 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"
 FORK=${INFO[1]}
 REPO=${INFO[2]}
-BRANCH=${INFO[4]}
+BRANCH=${INFO[5]}
 
 git push --set-upstream origin $BRANCH
 
diff --git a/buildroot/share/git/mfadd b/buildroot/share/git/mfadd
index 6d69124498..8b6ded3666 100755
--- a/buildroot/share/git/mfadd
+++ b/buildroot/share/git/mfadd
@@ -5,20 +5,16 @@
 # 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"
-
 REPO=${INFO[2]}
-OLDBRANCH=${INFO[4]}
-
-case "$#" in
-  1 ) USER=$1 ;;
-  * ) echo "Usage: `basename $0` [user]" 1>&2 ; exit 1 ;;
-esac
 
 set -e
 
 echo "Adding and fetching $USER..."
-
-git remote add -f "$USER" "git@github.com:$USER/$REPO.git"
+git remote add "$USER" "git@github.com:$USER/$REPO.git"
+git fetch "$USER"
diff --git a/buildroot/share/git/mfclean b/buildroot/share/git/mfclean
index 4ce0faa8f5..99fd227d2c 100755
--- a/buildroot/share/git/mfclean
+++ b/buildroot/share/git/mfclean
@@ -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
 echo
 
+# List fork branches that don't match local branches
 echo "You may want to remove (or checkout) these refs..."
 comm -23 \
   <(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; }') \
-  | 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
diff --git a/buildroot/share/git/mfdoc b/buildroot/share/git/mfdoc
index 4b28e9ca14..dde571dd04 100755
--- a/buildroot/share/git/mfdoc
+++ b/buildroot/share/git/mfdoc
@@ -5,16 +5,15 @@
 # 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"
 ORG=${INFO[0]}
 REPO=${INFO[2]}
-BRANCH=${INFO[4]}
+BRANCH=${INFO[5]}
 
-if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
-  echo "Wrong repository."
-  exit
-fi
+[[ $ORG == "MarlinFirmware" && $REPO == "MarlinDocumentation" ]] || { echo "Wrong repository." 1>&2; exit 1; }
 
 opensite() {
   TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
diff --git a/buildroot/share/git/mfinfo b/buildroot/share/git/mfinfo
index e22744fe90..febbcc3ecf 100755
--- a/buildroot/share/git/mfinfo
+++ b/buildroot/share/git/mfinfo
@@ -2,27 +2,25 @@
 #
 # 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 (origin) Org name (your Github username)
-#   - Repo Name (Marlin or MarlinDev)
-#   - Marlin Target branch (RCBugFix or dev)
-#   - Branch Name (the current branch or the one that was passed)
+#   - Repo Name (Marlin, MarlinDev, MarlinDocumentation)
+#   - PR Target branch (bugfix-1.1.x, dev, or master)
+#   - 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
-  echo "`basename $0`: No 'upstream' remote found." 1>&2 ; exit 1
-fi
+REPO=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*\/(.*)\.git/\1/')
+[[ -z $REPO ]] && { echo "`basename $0`: No 'upstream' remote found. (Did you run mfinit?)" 1>&2 ; exit 1; }
 
 ORG=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
-
-if [[ $ORG != MarlinFirmware ]]; then
-  echo "`basename $0`: Not a Marlin repository."
-  exit 1
-fi
+[[ $ORG == MarlinFirmware ]] || { echo "`basename $0`: Not a Marlin repository." 1>&2 ; exit 1; }
 
 case "$REPO" in
   Marlin              ) TARG=bugfix-1.1.x ;;
@@ -33,13 +31,9 @@ esac
 FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
 
 case "$#" in
-  0 ) BRANCH=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g') ;;
+  0 ) BRANCH=$CURR ;;
   1 ) BRANCH=$1 ;;
   * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
 esac
 
-if [[ $BRANCH == "(no" ]]; then
-  echo "Git is busy with merge, rebase, etc." 1>&2 ; exit 1
-fi
-
-echo "$ORG $FORK $REPO $TARG $BRANCH"
+echo "$ORG $FORK $REPO $TARG $BRANCH $CURR"
diff --git a/buildroot/share/git/mfinit b/buildroot/share/git/mfinit
index 2a37914601..05bab8767d 100755
--- a/buildroot/share/git/mfinit
+++ b/buildroot/share/git/mfinit
@@ -5,12 +5,13 @@
 # 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/')
+[[ -z $REPO ]] && { echo "`basename $0`: No 'origin' remote found." 1>&2 ; exit 1; }
 
-if [[ -z $REPO ]]; then
-  echo "`basename $0`: No 'origin' remote found." 1>&2 ; exit 1
-fi
-
+echo "Adding 'upstream' remote for convenience."
 git remote add upstream "git@github.com:MarlinFirmware/$REPO.git"
-
-git fetch upstream
\ No newline at end of file
+git fetch upstream
diff --git a/buildroot/share/git/mfnew b/buildroot/share/git/mfnew
index 42f233bf64..f1e495cbc4 100755
--- a/buildroot/share/git/mfnew
+++ b/buildroot/share/git/mfnew
@@ -5,14 +5,15 @@
 # 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"
 TARG=${INFO[3]}
 
 case "$#" in
   0 ) BRANCH=pr_for_$TARG-$(date +"%G-%m-%d_%H.%M.%S") ;;
   1 ) BRANCH=$1 ;;
-  * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
 esac
 
 git fetch upstream
diff --git a/buildroot/share/git/mfpr b/buildroot/share/git/mfpr
index eb2e102aed..025b68692f 100755
--- a/buildroot/share/git/mfpr
+++ b/buildroot/share/git/mfpr
@@ -5,22 +5,22 @@
 # 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"
-
 ORG=${INFO[0]}
 FORK=${INFO[1]}
 REPO=${INFO[2]}
 TARG=${INFO[3]}
 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
-  echo "Can't make a PR from $BRANCH" ; exit
-fi
+[[ $BRANCH != $OLDBRANCH ]] && { git checkout $BRANCH || exit 1; }
 
+# See if it's been pushed yet
 if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
 
 TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
@@ -33,3 +33,5 @@ else
   echo "Opening a New PR Form..."
   "$TOOL" "$URL"
 fi
+
+[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
diff --git a/buildroot/share/git/mfpub b/buildroot/share/git/mfpub
index 9e590eb074..9b48480d0e 100755
--- a/buildroot/share/git/mfpub
+++ b/buildroot/share/git/mfpub
@@ -9,7 +9,9 @@
 # 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"
 ORG=${INFO[0]}
 FORK=${INFO[1]}
diff --git a/buildroot/share/git/mfqp b/buildroot/share/git/mfqp
index 67a385c2ef..97cac5dbef 100755
--- a/buildroot/share/git/mfqp
+++ b/buildroot/share/git/mfqp
@@ -5,26 +5,22 @@
 # 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"
+REPO=${INFO[2]}
+TARG=${INFO[3]}
+BRANCH=${INFO[5]}
 
-if [[ ${INFO[4]} == "(no" ]]; then
-  echo "Branch is unavailable!" ; exit 1
-fi
-
-case "$#" in
-  0 ) ;;
-  * ) echo "Usage: `basename $0`" 1>&2 ; exit 1 ;;
-esac
-
-git add * .travis.yml
+git add .
 git commit -m "patch"
 
-if [[ ${INFO[3]} == ${INFO[4]} ]]; then
-  if [[ ${INFO[2]} == "MarlinDocumentation" ]]; then
+if [[ $BRANCH == $TARG ]]; then
+  if [[ $REPO == "MarlinDocumentation" ]]; then
     git rebase -i HEAD~2
   else
-    echo "Don't alter the PR target branch."; exit 1
+    echo "Don't alter the PR Target branch."; exit 1
   fi
 else
   mfrb
diff --git a/buildroot/share/git/mfrb b/buildroot/share/git/mfrb
index 954556d0e0..b376b40746 100755
--- a/buildroot/share/git/mfrb
+++ b/buildroot/share/git/mfrb
@@ -5,16 +5,15 @@
 # Do "git rebase -i" against the "target" branch (RCBugFix or dev)
 #
 
-MFINFO=$(mfinfo) || exit
-IFS=' ' read -a INFO <<< "$MFINFO"
+[[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
 
-case "$#" in
-  0 ) ;;
-  * ) echo "Usage: `basename $0`" 1>&2 ; exit 1 ;;
-esac
+MFINFO=$(mfinfo) || exit 1
+IFS=' ' read -a INFO <<< "$MFINFO"
+TARG=${INFO[3]}
+BRANCH=${INFO[5]}
 
 # If the branch isn't currently the PR target
-if [[ ${INFO[3]} != ${INFO[4]} ]]; then
+if [[ $TARG != $BRANCH ]]; then
   git fetch upstream
-  git rebase upstream/${INFO[3]} && git rebase -i upstream/${INFO[3]}
+  git rebase upstream/$TARG && git rebase -i upstream/$TARG
 fi
diff --git a/buildroot/share/git/mfup b/buildroot/share/git/mfup
index 8d339c0685..cb6abda9ae 100755
--- a/buildroot/share/git/mfup
+++ b/buildroot/share/git/mfup
@@ -2,47 +2,55 @@
 #
 # 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"
-
 ORG=${INFO[0]}
 FORK=${INFO[1]}
 REPO=${INFO[2]}
 TARG=${INFO[3]}
-OLDBRANCH=${INFO[4]}
-
-case "$#" in
-  0 ) BRANCH=$OLDBRANCH ;;
-  1 ) BRANCH=$1 ;;
-  * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
-esac
+BRANCH=${INFO[4]}
+OLDBRANCH=${INFO[5]}
 
 set -e
 
+# Prevent accidental loss of current changes
+[[ $(git stash) != "No local "* ]] && HAS_STASH=1
+
 echo "Fetching upstream ($ORG/$REPO)..."
 git fetch upstream
 
 echo ; echo "Bringing $TARG up to date..."
-git checkout -q $TARG || git branch checkout upstream/$TARG -b $TARG && git push --set-upstream origin $TARG
-git merge upstream/$TARG
-git push origin
+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
   echo ; echo "Rebasing $BRANCH on $TARG..."
   if git checkout $BRANCH; then
     echo
     if git rebase $TARG; then
-      git push -f ; echo
-      [[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
+      git push -f
     else
-      echo "Looks like merge conflicts. Stopping here."
+      echo "Looks like merge conflicts. Stopping here." ; exit
     fi
   else
-    echo "No such branch!" ; echo
-    git checkout $OLDBRANCH
+    echo "No such branch!"
   fi
 fi
+
+echo
+[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
+
+[[ $HAS_STASH == 1 ]] && git stash pop

From e1e1a0c344d987acba62b7c1164cee9ed363f714 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Sun, 2 Jul 2017 22:35:28 -0500
Subject: [PATCH 2/4] Provide a default CUSTOM_BOOTSCREEN_TIMEOUT

---
 Marlin/Marlin_main.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index 81fdda8047..39f090b256 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -13031,6 +13031,10 @@ void setup() {
 
   lcd_init();
 
+  #ifndef CUSTOM_BOOTSCREEN_TIMEOUT
+    #define CUSTOM_BOOTSCREEN_TIMEOUT 2500
+  #endif
+
   #if ENABLED(SHOW_BOOTSCREEN)
     #if ENABLED(DOGLCD)                           // On DOGM the first bootscreen is already drawn
       #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)

From 534bffa7a97a8970bbf5146059744adeb13a901f Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Mon, 3 Jul 2017 01:08:59 -0500
Subject: [PATCH 3/4] Correct comment on ABL G29

---
 Marlin/Marlin_main.cpp | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index 39f090b256..7cd18b02be 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -4228,10 +4228,14 @@ void home_all_axes() { gcode_G28(true); }
    *
    *  A  Abort current leveling procedure
    *
-   *  W  Write a mesh point. (Ignored during leveling.)
-   *  X  Required X for mesh point
-   *  Y  Required Y for mesh point
-   *  Z  Z for mesh point. Otherwise, current Z minus Z probe offset.
+   * Extra parameters with BILINEAR only:
+   *
+   *  W  Write a mesh point. (If G29 is idle.)
+   *  I  X index for mesh point
+   *  J  Y index for mesh point
+   *  X  X for mesh point, overrides I
+   *  Y  Y for mesh point, overrides J
+   *  Z  Z for mesh point. Otherwise, raw current Z.
    *
    * Without PROBE_MANUALLY:
    *

From 6a3967ee331d1816f7bb4f246c95d5ddcae1f100 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Mon, 3 Jul 2017 01:09:34 -0500
Subject: [PATCH 4/4] Corrections for probe_pt parameters

---
 Marlin/Marlin_main.cpp | 2 +-
 Marlin/ubl_G29.cpp     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index 7cd18b02be..9eb09cff0b 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -2299,7 +2299,7 @@ static void clean_up_after_endstop_or_probe_move() {
    *   - Raise to the BETWEEN height
    * - Return the probed Z position
    */
-  float probe_pt(const float &x, const float &y, const bool stow/*=true*/, const int verbose_level/*=1*/) {
+  float probe_pt(const float &x, const float &y, const bool stow, const uint8_t verbose_level) {
     #if ENABLED(DEBUG_LEVELING_FEATURE)
       if (DEBUGGING(LEVELING)) {
         SERIAL_ECHOPAIR(">>> probe_pt(", x);
diff --git a/Marlin/ubl_G29.cpp b/Marlin/ubl_G29.cpp
index e0b27cb9c0..d8a26c1353 100644
--- a/Marlin/ubl_G29.cpp
+++ b/Marlin/ubl_G29.cpp
@@ -51,7 +51,7 @@
 
   extern float meshedit_done;
   extern long babysteps_done;
-  extern float probe_pt(const float &x, const float &y, bool, int);
+  extern float probe_pt(const float &x, const float &y, const bool, const uint8_t);
   extern bool set_probe_deployed(bool);
   extern void set_bed_leveling_enabled(bool);
   typedef void (*screenFunc_t)();