Tweak git helper scripts

master
Scott Lahteine 8 years ago
parent 771f42744a
commit d0480c15ef

@ -0,0 +1,60 @@
## Marlin Github Helper Scripts
### Introduction
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.
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.
#### Merge vs Rebase
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.
### The Scripts
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.
#### Remotes
File|Description
----|-----------
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`.
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.
#### Branches
File|Description
----|-----------
mfnew [branch]|New Branch - Creates a new branch based on `upstream/[PR-target]`. All new work should start here.
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.
#### Making / Amending PRs
File|Description
----|-----------
mfpr|Pull Request - Open the Compare / Pull Request page on Github for the current branch.
mfrb|Do a `git rebase` then `git rebase -i` of the current branch onto `upstream/[PR-target]`. Use this to edit your commits anytime.
mfqp|Quick Patch - Commit all current changes as "patch", `mfrb`, and `git push -f`.
#### Documentation
File|Description
----|-----------
mfdoc|Build the documentation and preview it locally.
mfpub|Build the documentation and publish it to marlinfw.org via Github.
#### Utilities
File|Description
----|-----------
ghtp -[h/s]|Set the protocol to use for all remotes. -h for HTTPS, -s for SSL.
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.
mfclean&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Prune your merged and remotely-deleted branches.
---
### Examples
Coming Soon!

@ -1,22 +1,24 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# mfprune # mfclean
# #
# Prune all your merged branches and any branches whose remotes are gone # Prune all your merged branches and any branches whose remotes are gone
# Great way to clean up your branches after messing around a lot # Great way to clean up your branches after messing around a lot
# #
KEEP="RC|RCBugFix|dev|master|bugfix-1"
echo "Fetching latest upstream and origin..." echo "Fetching latest upstream and origin..."
git fetch upstream git fetch upstream
git fetch origin git fetch origin
echo echo
echo "Pruning Merged Branches..." echo "Pruning Merged Branches..."
git branch --merged | egrep -v "^\*|RC|RCBugFix|dev" | xargs -n 1 git branch -d git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d
echo echo
echo "Pruning Remotely-deleted Branches..." echo "Pruning Remotely-deleted Branches..."
git branch -vv | egrep -v "^\*|RC|RCBugFix|dev" | 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
echo "You may want to remove (or checkout) these refs..." echo "You may want to remove (or checkout) these refs..."

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

@ -2,7 +2,11 @@
# #
# mfpub # mfpub
# #
# Use Jekyll to publish Marlin Documentation to the HTML site # Use Jekyll to generate Marlin Documentation, which is then
# git-pushed to Github to publish it to the live site.
# This publishes the current branch, and doesn't force
# changes to be pushed to the 'master' branch. Be sure to push
# any permanent changes to 'master'.
# #
MFINFO=$(mfinfo "$@") || exit MFINFO=$(mfinfo "$@") || exit
@ -19,23 +23,22 @@ if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
fi fi
if [[ $BRANCH == "gh-pages" ]]; then if [[ $BRANCH == "gh-pages" ]]; then
echo "Can't build from 'gh-pages.' Only the Jekyll branches." echo "Can't build from 'gh-pages.' Only the Jekyll branches (based on 'master')."
bundle exec jekyll serve --watch bundle exec jekyll serve --watch
exit exit
fi fi
if [[ $BRANCH != "master" ]]; then if [[ $BRANCH != "master" ]]; then
echo "Don't forget to update and push 'master'!" echo "Don't forget to update and push 'master'!"
# GOJF Card
git stash
fi fi
# Check out the named branch (or stay in current)
git checkout $BRANCH git checkout $BRANCH
echo "Generating MarlinDocumentation..." echo "Generating MarlinDocumentation..."
# GOJF Card
git stash
TMPFOLDER=$( mktemp -d )
COMMIT=$( git log --format="%H" -n 1 ) COMMIT=$( git log --format="%H" -n 1 )
# Clean out changes and other junk in the branch # Clean out changes and other junk in the branch
@ -45,6 +48,13 @@ git clean -d -f
# Push 'master' to the fork and make a proper PR... # Push 'master' to the fork and make a proper PR...
if [[ $BRANCH == "master" ]]; then if [[ $BRANCH == "master" ]]; then
if [[ $$FORK == "MarlinFirmware" ]]; then
# Allow working directly with the main fork
git push -f upstream
else
if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
git push -f origin git push -f origin
@ -62,13 +72,18 @@ if [[ $BRANCH == "master" ]]; then
fi fi
fi
# Uncomment to compress the final html files # Uncomment to compress the final html files
# mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb # mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
# bundle install # bundle install
# build the site statically and proof it
bundle exec jekyll build --profile --trace --no-watch bundle exec jekyll build --profile --trace --no-watch
bundle exec htmlproofer ./_site --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/" bundle exec htmlproofer ./_site --only-4xx --allow-hash-href --check-favicon --check-html --url-swap ".*marlinfw.org/:/"
# Sync the built site into a temporary folder
TMPFOLDER=$( mktemp -d )
rsync -av _site/ ${TMPFOLDER}/ rsync -av _site/ ${TMPFOLDER}/
# Clean out changes and other junk in the branch # Clean out changes and other junk in the branch
@ -84,6 +99,7 @@ git add --all
git commit --message "Built from ${COMMIT}" git commit --message "Built from ${COMMIT}"
git push upstream git push upstream
# remove the temporary folder
rm -rf ${TMPFOLDER} rm -rf ${TMPFOLDER}
# Go back to the branch we started from # Go back to the branch we started from

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

Loading…
Cancel
Save