Browse Source

Tweak git helper scripts

Scott Lahteine 7 years ago
parent
commit
d14b068147

+ 60
- 0
buildroot/share/git/README.md View File

@@ -0,0 +1,60 @@
1
+## Marlin Github Helper Scripts
2
+
3
+### Introduction
4
+
5
+A Pull Request is often just the start of a longer process of patching and refining the code until it's ready to merge. In that process it's common to accumulate a lot of commits, some of which are non-functional. Before merging any PR, excess commits need to be "squashed" and sometimes rearranged or reworked to produce a well-packaged set of changes and keep the commit history relatively clean.
6
+
7
+In addition, while a PR is being worked on other commits may be merged, leading to conflicts that need resolution. For this reason, it's a best practice to periodically refresh the PR so the working copy closely reflects the final merge.
8
+
9
+#### Merge vs Rebase
10
+
11
+I recommend not using Github Desktop to sync and merge. Use the command line instead. Github Desktop provides a "merge" option, but for best results "`git rebase`" is recommended. Merge applies new work after your commits. This buries them and makes it hard to bring them together as a final packaged unit. Rebase moves your commits to the end of the branch, ensuring that your commits will be adapted to the current code. This makes it easier to keep revising the commits in-place.
12
+
13
+### The Scripts
14
+
15
+The following scripts can be used on macOS or Linux to speed up the process of working with Marlin and submitting changes to the project.
16
+
17
+#### Remotes
18
+
19
+File|Description
20
+----|-----------
21
+mfadd [user]|Add Remote - Add another Github user's fork of Marlin as a remote, then fetch it. After this you can check out one of their branches and either make a PR targeted at their fork or targeted at `bugfix-1.1.x`.
22
+mfinit|Init Working Copy - Creates a remote named '`upstream`' (for use by the other scripts) pointing to the '`MarlinFirmware`' fork. Use once after checking out your fork.
23
+
24
+
25
+#### Branches
26
+
27
+File|Description
28
+----|-----------
29
+mfnew [branch]|New Branch - Creates a new branch based on `upstream/[PR-target]`. All new work should start here.
30
+firstpush|Push the current branch to 'origin' -your fork on Github- and set it to track '`origin`'. The branch needs to reside on Github before you can use it to make a PR.
31
+
32
+
33
+#### Making / Amending PRs
34
+
35
+File|Description
36
+----|-----------
37
+mfpr|Pull Request - Open the Compare / Pull Request page on Github for the current branch.
38
+mfrb|Do a `git rebase` then `git rebase -i` of the current branch onto `upstream/[PR-target]`. Use this to edit your commits anytime.
39
+mfqp|Quick Patch - Commit all current changes as "patch", `mfrb`, and `git push -f`.
40
+
41
+#### Documentation
42
+
43
+File|Description
44
+----|-----------
45
+mfdoc|Build the documentation and preview it locally.
46
+mfpub|Build the documentation and publish it to marlinfw.org via Github.
47
+
48
+#### Utilities
49
+
50
+File|Description
51
+----|-----------
52
+ghtp -[h/s]|Set the protocol to use for all remotes. -h for HTTPS, -s for SSL.
53
+mfinfo|This utility script is used by the other scripts to get:<br/>- The upstream project ('`MarlinFirmware`')<br/>- the '`origin`' project (i.e., your Github username),<br/>- the repository name ('`Marlin`'),<br/>- the PR target branch ('`bugfix-1.1.x`'), and<br/>- the current branch (or the first command-line argument).<br/><br/>By itself, `mfinfo` simply prints these values to the console.
54
+mfclean&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Prune your merged and remotely-deleted branches.
55
+
56
+---
57
+
58
+### Examples
59
+
60
+Coming Soon!

buildroot/share/git/mfprune → buildroot/share/git/mfclean View File

@@ -1,22 +1,24 @@
1 1
 #!/usr/bin/env bash
2 2
 #
3
-# mfprune
3
+# mfclean
4 4
 #
5 5
 # Prune all your merged branches and any branches whose remotes are gone
6 6
 # Great way to clean up your branches after messing around a lot
7 7
 #
8 8
 
9
+KEEP="RC|RCBugFix|dev|master|bugfix-1"
10
+
9 11
 echo "Fetching latest upstream and origin..."
10 12
 git fetch upstream
11 13
 git fetch origin
12 14
 echo
13 15
 
14 16
 echo "Pruning Merged Branches..."
15
-git branch --merged | egrep -v "^\*|RC|RCBugFix|dev" | xargs -n 1 git branch -d
17
+git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d
16 18
 echo
17 19
 
18 20
 echo "Pruning Remotely-deleted Branches..."
19
-git branch -vv | egrep -v "^\*|RC|RCBugFix|dev" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D
21
+git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D
20 22
 echo
21 23
 
22 24
 echo "You may want to remove (or checkout) these refs..."

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

@@ -15,4 +15,5 @@ case "$#" in
15 15
   * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
16 16
 esac
17 17
 
18
-git checkout $TARG -b $BRANCH
18
+git fetch upstream
19
+git checkout upstream/$TARG -b $BRANCH

+ 32
- 16
buildroot/share/git/mfpub View File

@@ -2,7 +2,11 @@
2 2
 #
3 3
 # mfpub
4 4
 #
5
-# Use Jekyll to publish Marlin Documentation to the HTML site
5
+# Use Jekyll to generate Marlin Documentation, which is then
6
+# git-pushed to Github to publish it to the live site.
7
+# This publishes the current branch, and doesn't force
8
+# changes to be pushed to the 'master' branch. Be sure to push
9
+# any permanent changes to 'master'.
6 10
 #
7 11
 
8 12
 MFINFO=$(mfinfo "$@") || exit
@@ -19,23 +23,22 @@ if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
19 23
 fi
20 24
 
21 25
 if [[ $BRANCH == "gh-pages" ]]; then
22
-  echo "Can't build from 'gh-pages.' Only the Jekyll branches."
26
+  echo "Can't build from 'gh-pages.' Only the Jekyll branches (based on 'master')."
23 27
   bundle exec jekyll serve --watch
24 28
   exit
25 29
 fi
26 30
 
27 31
 if [[ $BRANCH != "master" ]]; then
28 32
   echo "Don't forget to update and push 'master'!"
33
+  # GOJF Card
34
+  git stash
29 35
 fi
30 36
 
37
+# Check out the named branch (or stay in current)
31 38
 git checkout $BRANCH
32 39
 
33 40
 echo "Generating MarlinDocumentation..."
34 41
 
35
-# GOJF Card
36
-git stash
37
-
38
-TMPFOLDER=$( mktemp -d )
39 42
 COMMIT=$( git log --format="%H" -n 1 )
40 43
 
41 44
 # Clean out changes and other junk in the branch
@@ -45,19 +48,28 @@ git clean -d -f
45 48
 # Push 'master' to the fork and make a proper PR...
46 49
 if [[ $BRANCH == "master" ]]; then
47 50
 
48
-  if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
49
-
50
-  git push -f origin
51
+  if [[ $$FORK == "MarlinFirmware" ]]; then
51 52
 
52
-  TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
53
-  URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
53
+    # Allow working directly with the main fork
54
+    git push -f upstream
54 55
 
55
-  if [ -z "$TOOL" ]; then
56
-    echo "Can't find a tool to open the URL:"
57
-    echo $URL
58 56
   else
59
-    echo "Opening a New PR Form..."
60
-    "$TOOL" "$URL"
57
+
58
+    if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
59
+
60
+    git push -f origin
61
+
62
+    TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
63
+    URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
64
+
65
+    if [ -z "$TOOL" ]; then
66
+      echo "Can't find a tool to open the URL:"
67
+      echo $URL
68
+    else
69
+      echo "Opening a New PR Form..."
70
+      "$TOOL" "$URL"
71
+    fi
72
+
61 73
   fi
62 74
 
63 75
 fi
@@ -66,9 +78,12 @@ fi
66 78
 # mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
67 79
 # bundle install
68 80
 
81
+# build the site statically and proof it
69 82
 bundle exec jekyll build --profile --trace --no-watch
70 83
 bundle exec htmlproofer ./_site --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/"
71 84
 
85
+# Sync the built site into a temporary folder
86
+TMPFOLDER=$( mktemp -d )
72 87
 rsync -av _site/ ${TMPFOLDER}/
73 88
 
74 89
 # Clean out changes and other junk in the branch
@@ -84,6 +99,7 @@ git add --all
84 99
 git commit --message "Built from ${COMMIT}"
85 100
 git push upstream
86 101
 
102
+# remove the temporary folder
87 103
 rm -rf ${TMPFOLDER}
88 104
 
89 105
 # Go back to the branch we started from

+ 5
- 1
buildroot/share/git/mfrb View File

@@ -13,4 +13,8 @@ case "$#" in
13 13
   * ) echo "Usage: `basename $0`" 1>&2 ; exit 1 ;;
14 14
 esac
15 15
 
16
-git rebase -i ${INFO[3]}
16
+# If the branch isn't currently the PR target
17
+if [[ ${INFO[4]} != ${INFO[5]} ]]; then
18
+  git fetch upstream
19
+  git rebase upstream/${INFO[3]} && git rebase -i upstream/${INFO[3]}
20
+fi

Loading…
Cancel
Save