Browse Source

Update Marlin+Github helper scripts

Scott Lahteine 7 years ago
parent
commit
ab79933d1f

+ 4
- 2
buildroot/share/git/firstpush View File

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

+ 6
- 10
buildroot/share/git/mfadd View File

@@ -5,20 +5,16 @@
5 5
 # Add a remote and fetch it
6 6
 #
7 7
 
8
-MFINFO=$(mfinfo) || exit
8
+[[ $# == 1 ]] || { echo "Usage: `basename $0` user" 1>&2 ; exit 1; }
9 9
 
10
-IFS=' ' read -a INFO <<< "$MFINFO"
10
+USER=$1
11 11
 
12
+MFINFO=$(mfinfo) || exit 1
13
+IFS=' ' read -a INFO <<< "$MFINFO"
12 14
 REPO=${INFO[2]}
13
-OLDBRANCH=${INFO[4]}
14
-
15
-case "$#" in
16
-  1 ) USER=$1 ;;
17
-  * ) echo "Usage: `basename $0` [user]" 1>&2 ; exit 1 ;;
18
-esac
19 15
 
20 16
 set -e
21 17
 
22 18
 echo "Adding and fetching $USER..."
23
-
24
-git remote add -f "$USER" "git@github.com:$USER/$REPO.git"
19
+git remote add "$USER" "git@github.com:$USER/$REPO.git"
20
+git fetch "$USER"

+ 2
- 1
buildroot/share/git/mfclean View File

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

+ 5
- 6
buildroot/share/git/mfdoc View File

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

+ 13
- 19
buildroot/share/git/mfinfo View File

@@ -2,27 +2,25 @@
2 2
 #
3 3
 # mfinfo
4 4
 #
5
-# Get the following helpful git info about the working directory:
5
+# Provide the following info about the working directory:
6 6
 #
7 7
 #   - Remote (upstream) Org name (MarlinFirmware)
8 8
 #   - Remote (origin) Org name (your Github username)
9
-#   - Repo Name (Marlin or MarlinDev)
10
-#   - Marlin Target branch (RCBugFix or dev)
11
-#   - Branch Name (the current branch or the one that was passed)
9
+#   - Repo Name (Marlin, MarlinDev, MarlinDocumentation)
10
+#   - PR Target branch (bugfix-1.1.x, dev, or master)
11
+#   - Branch Arg (the branch argument or current branch)
12
+#   - Current Branch
12 13
 #
13 14
 
14
-REPO=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*\/(.*)\.git/\1/')
15
+CURR=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g')
16
+[[ -z $CURR ]] && { echo "No git repository here!" 1>&2 ; exit 1; }
17
+[[ $CURR == "(no"* ]] && { echo "Git is busy with merge, rebase, etc." 1>&2 ; exit 1; }
15 18
 
16
-if [[ -z $REPO ]]; then
17
-  echo "`basename $0`: No 'upstream' remote found." 1>&2 ; exit 1
18
-fi
19
+REPO=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*\/(.*)\.git/\1/')
20
+[[ -z $REPO ]] && { echo "`basename $0`: No 'upstream' remote found. (Did you run mfinit?)" 1>&2 ; exit 1; }
19 21
 
20 22
 ORG=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
21
-
22
-if [[ $ORG != MarlinFirmware ]]; then
23
-  echo "`basename $0`: Not a Marlin repository."
24
-  exit 1
25
-fi
23
+[[ $ORG == MarlinFirmware ]] || { echo "`basename $0`: Not a Marlin repository." 1>&2 ; exit 1; }
26 24
 
27 25
 case "$REPO" in
28 26
   Marlin              ) TARG=bugfix-1.1.x ;;
@@ -33,13 +31,9 @@ esac
33 31
 FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
34 32
 
35 33
 case "$#" in
36
-  0 ) BRANCH=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g') ;;
34
+  0 ) BRANCH=$CURR ;;
37 35
   1 ) BRANCH=$1 ;;
38 36
   * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
39 37
 esac
40 38
 
41
-if [[ $BRANCH == "(no" ]]; then
42
-  echo "Git is busy with merge, rebase, etc." 1>&2 ; exit 1
43
-fi
44
-
45
-echo "$ORG $FORK $REPO $TARG $BRANCH"
39
+echo "$ORG $FORK $REPO $TARG $BRANCH $CURR"

+ 7
- 6
buildroot/share/git/mfinit View File

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

+ 3
- 2
buildroot/share/git/mfnew View File

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

+ 8
- 6
buildroot/share/git/mfpr View File

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

+ 3
- 1
buildroot/share/git/mfpub View File

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

+ 10
- 14
buildroot/share/git/mfqp View File

@@ -5,26 +5,22 @@
5 5
 # Add all changed files, commit as "patch", do `mfrb` and `git push -f`
6 6
 #
7 7
 
8
-MFINFO=$(mfinfo) || exit
9
-IFS=' ' read -a INFO <<< "$MFINFO"
10
-
11
-if [[ ${INFO[4]} == "(no" ]]; then
12
-  echo "Branch is unavailable!" ; exit 1
13
-fi
8
+[[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
14 9
 
15
-case "$#" in
16
-  0 ) ;;
17
-  * ) echo "Usage: `basename $0`" 1>&2 ; exit 1 ;;
18
-esac
10
+MFINFO=$(mfinfo) || exit 1
11
+IFS=' ' read -a INFO <<< "$MFINFO"
12
+REPO=${INFO[2]}
13
+TARG=${INFO[3]}
14
+BRANCH=${INFO[5]}
19 15
 
20
-git add * .travis.yml
16
+git add .
21 17
 git commit -m "patch"
22 18
 
23
-if [[ ${INFO[3]} == ${INFO[4]} ]]; then
24
-  if [[ ${INFO[2]} == "MarlinDocumentation" ]]; then
19
+if [[ $BRANCH == $TARG ]]; then
20
+  if [[ $REPO == "MarlinDocumentation" ]]; then
25 21
     git rebase -i HEAD~2
26 22
   else
27
-    echo "Don't alter the PR target branch."; exit 1
23
+    echo "Don't alter the PR Target branch."; exit 1
28 24
   fi
29 25
 else
30 26
   mfrb

+ 7
- 8
buildroot/share/git/mfrb View File

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

+ 26
- 18
buildroot/share/git/mfup View File

@@ -2,47 +2,55 @@
2 2
 #
3 3
 # mfup
4 4
 #
5
-# Fetch and merge upstream changes, optionally with a branch
5
+# - Fetch latest upstream and replace the PR Target branch with 
6
+# - Rebase the (current or specified) branch on the PR Target
7
+# - Force-push the branch to 'origin'
8
+# - 
6 9
 #
7 10
 
8
-MFINFO=$(mfinfo) || exit
11
+[[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
9 12
 
13
+MFINFO=$(mfinfo "$@") || exit 1
10 14
 IFS=' ' read -a INFO <<< "$MFINFO"
11
-
12 15
 ORG=${INFO[0]}
13 16
 FORK=${INFO[1]}
14 17
 REPO=${INFO[2]}
15 18
 TARG=${INFO[3]}
16
-OLDBRANCH=${INFO[4]}
17
-
18
-case "$#" in
19
-  0 ) BRANCH=$OLDBRANCH ;;
20
-  1 ) BRANCH=$1 ;;
21
-  * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
22
-esac
19
+BRANCH=${INFO[4]}
20
+OLDBRANCH=${INFO[5]}
23 21
 
24 22
 set -e
25 23
 
24
+# Prevent accidental loss of current changes
25
+[[ $(git stash) != "No local "* ]] && HAS_STASH=1
26
+
26 27
 echo "Fetching upstream ($ORG/$REPO)..."
27 28
 git fetch upstream
28 29
 
29 30
 echo ; echo "Bringing $TARG up to date..."
30
-git checkout -q $TARG || git branch checkout upstream/$TARG -b $TARG && git push --set-upstream origin $TARG
31
-git merge upstream/$TARG
32
-git push origin
31
+if [[ git checkout -q $TARG ]]; then
32
+  git reset --hard upstream/$TARG
33
+  git push -f origin
34
+else
35
+  git checkout upstream/$TARG -b $TARG
36
+  git push --set-upstream origin $TARG
37
+fi
33 38
 
34 39
 if [[ $BRANCH != $TARG ]]; then
35 40
   echo ; echo "Rebasing $BRANCH on $TARG..."
36 41
   if git checkout $BRANCH; then
37 42
     echo
38 43
     if git rebase $TARG; then
39
-      git push -f ; echo
40
-      [[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
44
+      git push -f
41 45
     else
42
-      echo "Looks like merge conflicts. Stopping here."
46
+      echo "Looks like merge conflicts. Stopping here." ; exit
43 47
     fi
44 48
   else
45
-    echo "No such branch!" ; echo
46
-    git checkout $OLDBRANCH
49
+    echo "No such branch!"
47 50
   fi
48 51
 fi
52
+
53
+echo
54
+[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
55
+
56
+[[ $HAS_STASH == 1 ]] && git stash pop

Loading…
Cancel
Save