Browse Source

Enhance github helper scripts (#9888)

Scott Lahteine 6 years ago
parent
commit
b9303b5577
No account linked to committer's email address

+ 9
- 10
buildroot/share/git/README.md View File

@@ -4,39 +4,38 @@
4 4
 
5 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 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.
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 into upstream `MarlinFirmware`.
8 8
 
9 9
 #### Merge vs Rebase
10 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.
11
+If you plan to create PRs and work on them after submission I recommend not using Github Desktop to sync and merge. Use the command line instead. Github Desktop provides a "merge" option, but I've found that "`git rebase`" is much cleaner and easier to manage. Merge applies new work _after_ your commits, which buries them deeper in the commit history and makes it hard to bring them together as a final packaged unit. Rebase helpfully moves your commits to the tip of the branch, ensuring that your commits are adapted to the current code. This makes it easier to keep revising the commits in-place.
12 12
 
13 13
 ### The Scripts
14 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.
15
+The following scripts can be used on any system with a GNU environment to speed up the process of working with Marlin branches and submitting changes to the project.
16 16
 
17 17
 #### Remotes
18 18
 
19 19
 File|Description
20 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-2.0.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
-
21
+mfadd [user]|Add and Fetch Remote - Add another Github user's fork of Marlin as a remote, then fetch it. Optionally, check out one of their branches.
22
+mfinit|Init Working Copy - Create a remote named '`upstream`' (for use by the other scripts) pointing to the '`MarlinFirmware`' fork. This only needs to be used once. Newer versions of Github Desktop may create `upstream` on your behalf.
24 23
 
25 24
 #### Branches
26 25
 
27 26
 File|Description
28 27
 ----|-----------
29
-mfnew [branch]|New Branch - Creates a new branch based on `upstream/[PR-target]`. All new work should start here.
28
+mfnew [branch]|New Branch - Creates a new branch based on `upstream/[PR-target]`. All new work should start with this command.
29
+mffp|Fast Push - Push the HEAD or a commit ID to `upstream` immediately. Requires privileged access to the MarlinFirmware repo.
30 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 31
 
32
-
33 32
 #### Making / Amending PRs
34 33
 
35 34
 File|Description
36 35
 ----|-----------
37 36
 mfpr|Pull Request - Open the Compare / Pull Request page on Github for the current branch.
38 37
 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`.
38
+mfqp|Quick Patch - Commit all current changes as "patch", then do `mfrb`, followed by `git push -f` if no conflicts need resolution.
40 39
 
41 40
 #### Documentation
42 41
 
@@ -50,7 +49,7 @@ mfpub|Build the documentation and publish it to marlinfw.org via Github.
50 49
 File|Description
51 50
 ----|-----------
52 51
 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-2.0.x`'), and<br/>- the current branch (or the first command-line argument).<br/><br/>By itself, `mfinfo` simply prints these values to the console.
52
+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 53
 mfclean&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Prune your merged and remotely-deleted branches.
55 54
 
56 55
 ---

+ 16
- 4
buildroot/share/git/mfadd View File

@@ -2,12 +2,22 @@
2 2
 #
3 3
 # mfadd
4 4
 #
5
-# Add a remote and fetch it
5
+# Add a remote and fetch it. Optionally copy a branch.
6
+#
7
+# Example: mfadd thinkyhead:patch-1 copy_of_patch-1
6 8
 #
7 9
 
8
-[[ $# == 1 ]] || { echo "Usage: `basename $0` user" 1>&2 ; exit 1; }
10
+[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` (user | ref copyname)" 1>&2 ; exit 1; }
9 11
 
10
-USER=$1
12
+# If a colon is included, split the parts
13
+if [[ $1 =~ ":" ]]; then
14
+  IFS=':' read -a DATA <<< "$1"
15
+  USER=${DATA[0]}
16
+  BRANCH=${DATA[1]}
17
+  NAME=$2
18
+else
19
+  USER=$1
20
+fi
11 21
 
12 22
 MFINFO=$(mfinfo) || exit 1
13 23
 IFS=' ' read -a INFO <<< "$MFINFO"
@@ -16,5 +26,7 @@ REPO=${INFO[2]}
16 26
 set -e
17 27
 
18 28
 echo "Adding and fetching $USER..."
19
-git remote add "$USER" "git@github.com:$USER/$REPO.git"
29
+git remote add "$USER" "git@github.com:$USER/$REPO.git" >/dev/null 2>&1 || echo "Remote exists."
20 30
 git fetch "$USER"
31
+
32
+[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout $USER/$BRANCH -b $NAME

+ 1
- 1
buildroot/share/git/mffp View File

@@ -6,7 +6,7 @@
6 6
 # By default: `git push upstream HEAD:bugfix-1.1.x`
7 7
 #
8 8
 
9
-[[ $# < 3 ]] || { echo "Usage: `basename $0` [1|2] [commit-id]" 1>&2 ; exit 1; }
9
+[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [1|2] [commit-id]" 1>&2 ; exit 1; }
10 10
 
11 11
 if [[ $1 == '1' || $1 == '2' ]]; then
12 12
   MFINFO=$(mfinfo "$1") || exit 1

+ 2
- 0
buildroot/share/git/mfinfo View File

@@ -16,6 +16,8 @@ usage() {
16 16
   echo "Usage: `basename $0` [1|2] [branch]" 1>&2
17 17
 }
18 18
 
19
+[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { usage; exit 1; }
20
+
19 21
 CURR=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g')
20 22
 [[ -z $CURR ]] && { echo "No git repository here!" 1>&2 ; exit 1; }
21 23
 [[ $CURR == "(no"* ]] && { echo "Git is busy with merge, rebase, etc." 1>&2 ; exit 1; }

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

@@ -9,7 +9,7 @@ usage() {
9 9
   echo "Usage: `basename $0` [1|2] [name]" 1>&2
10 10
 }
11 11
 
12
-[[ $# < 3 ]] || { usage ; exit 1 ; }
12
+[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { usage; exit 1; }
13 13
 
14 14
 MFINFO=$(mfinfo "$@") || exit 1
15 15
 IFS=' ' read -a INFO <<< "$MFINFO"

+ 1
- 1
buildroot/share/git/mfpr View File

@@ -5,7 +5,7 @@
5 5
 # Make a PR of the current branch against RCBugFix or dev
6 6
 #
7 7
 
8
-[[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
8
+[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
9 9
 
10 10
 MFINFO=$(mfinfo "$@") || exit 1
11 11
 IFS=' ' read -a INFO <<< "$MFINFO"

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

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

+ 1
- 1
buildroot/share/git/mfqp View File

@@ -5,7 +5,7 @@
5 5
 # Add all changed files, commit as "patch", do `mfrb` and `git push -f`
6 6
 #
7 7
 
8
-[[ $# < 2 ]] || { echo "Usage: `basename $0` [1|2]" 1>&2 ; exit 1; }
8
+[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [1|2]" 1>&2 ; exit 1; }
9 9
 
10 10
 MFINFO=$(mfinfo "$@") || exit 1
11 11
 IFS=' ' read -a INFO <<< "$MFINFO"

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

@@ -5,7 +5,7 @@
5 5
 # Do "git rebase -i" against the "target" branch (bugfix-1.1.x, bugfix-2.0.x, or master)
6 6
 #
7 7
 
8
-[[ $# < 2 ]] || { echo "Usage: `basename $0` [1|2]" 1>&2 ; exit 1; }
8
+[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [1|2]" 1>&2 ; exit 1; }
9 9
 
10 10
 MFINFO=$(mfinfo "$@") || exit 1
11 11
 IFS=' ' read -a INFO <<< "$MFINFO"

+ 1
- 1
buildroot/share/git/mfup View File

@@ -7,7 +7,7 @@
7 7
 # - Force-push the branch to 'origin'
8 8
 #
9 9
 
10
-[[ $# < 3 ]] || { echo "Usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; }
10
+[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; }
11 11
 
12 12
 MFINFO=$(mfinfo "$@") || exit 1
13 13
 IFS=' ' read -a INFO <<< "$MFINFO"

Loading…
Cancel
Save