Initial commit
This commit is contained in:
60
buildroot/share/git/README.md
Executable file
60
buildroot/share/git/README.md
Executable file
@ -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 into upstream `MarlinFirmware`.
|
||||
|
||||
#### Merge vs Rebase
|
||||
|
||||
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.
|
||||
|
||||
### The Scripts
|
||||
|
||||
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.
|
||||
|
||||
#### Remotes
|
||||
|
||||
File|Description
|
||||
----|-----------
|
||||
mfadd [user]|Add and Fetch Remote - Add and fetch another user's Marlin fork. Optionally, check out one of their branches.
|
||||
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.
|
||||
|
||||
#### Branches
|
||||
|
||||
File|Description
|
||||
----|-----------
|
||||
mfnew [branch]|New Branch - Creates a new branch based on `upstream/[PR-target]`. All new work should start with this command.
|
||||
mffp|Fast Push - Push the HEAD or a commit ID to `upstream` immediately. Requires privileged access to the MarlinFirmware repo.
|
||||
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", then do `mfrb`, followed by `git push -f` if no conflicts need resolution.
|
||||
|
||||
#### Documentation
|
||||
|
||||
File|Description
|
||||
----|-----------
|
||||
mfdoc|Build the documentation with Jekyll and preview it locally.
|
||||
mfpub|Build and publish the documentation to marlinfw.org.
|
||||
|
||||
#### Utilities
|
||||
|
||||
File|Description
|
||||
----|-----------
|
||||
ghtp -[h/s]|Set the protocol to use for all remotes. -h for HTTPS, -s for SSL.
|
||||
ghpc [-f]|Push current branch to 'origin' or to the remote indicated by the error.
|
||||
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 |Prune your merged and remotely-deleted branches.
|
||||
|
||||
---
|
||||
|
||||
### Examples
|
||||
|
||||
For a demonstration of these scripts see the video [Marlin Live - May 9 2019](https://youtu.be/rwT4G0uVTIY). There is also an old write-up at [#3193](https://github.com/MarlinFirmware/Marlin/issues/3193).
|
28
buildroot/share/git/firstpush
Executable file
28
buildroot/share/git/firstpush
Executable file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# firstpush
|
||||
#
|
||||
# Push a branch to 'origin' and open the
|
||||
# commit log to watch Travis CI progress.
|
||||
#
|
||||
|
||||
[[ $# == 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[5]}
|
||||
|
||||
git push --set-upstream origin HEAD:$BRANCH
|
||||
|
||||
OPEN=$( which gnome-open xdg-open open | head -n1 )
|
||||
URL="https://github.com/$FORK/$REPO/commits/$BRANCH"
|
||||
|
||||
if [ -z "$OPEN" ]; then
|
||||
echo "Can't find a tool to open the URL:"
|
||||
echo $URL
|
||||
else
|
||||
echo "Viewing commits on $BRANCH..."
|
||||
"$OPEN" "$URL"
|
||||
fi
|
68
buildroot/share/git/ghpc
Executable file
68
buildroot/share/git/ghpc
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# ghpc (GitHub Push Current)
|
||||
#
|
||||
# - Push current branch to its remote. Try the following until it works:
|
||||
# - Plain 'git push'
|
||||
# - 'git push -f'
|
||||
# - Try the 'git push' command from the 'git push' error message
|
||||
# - Try adding '-f' to that command
|
||||
#
|
||||
|
||||
yay() { echo "SUCCESS" ; }
|
||||
boo() { echo "FAIL" ; }
|
||||
|
||||
FORCE=$([[ "$1" == "--force" || "$1" == "-f" ]] && echo 1)
|
||||
|
||||
if [[ ! $FORCE ]]; then
|
||||
echo -n "trying 'git push' ...... "
|
||||
git push >/dev/null 2>&1 && { yay ; exit ; }
|
||||
boo
|
||||
fi
|
||||
|
||||
echo -n "trying 'git push -f' ... "
|
||||
|
||||
# Get the error output from the failed push
|
||||
# and get the recommended 'git push' line
|
||||
git push -f 2>&1 | {
|
||||
CMD=""
|
||||
|
||||
ltrim() {
|
||||
[[ "$1" =~ [^[:space:]].* ]]
|
||||
printf "%s" "$BASH_REMATCH"
|
||||
}
|
||||
|
||||
while IFS= read -r line
|
||||
do
|
||||
#echo "$line"
|
||||
if [[ -z "$CMD" && $line =~ "git push" ]]; then
|
||||
CMD=$(ltrim "$line")
|
||||
fi
|
||||
done
|
||||
|
||||
# if a command was found try it
|
||||
if [[ -n "$CMD" ]]; then
|
||||
|
||||
boo
|
||||
|
||||
if [[ ! $FORCE ]]; then
|
||||
echo -n "trying '$CMD' ...... "
|
||||
$CMD >/dev/null 2>&1 && { yay ; exit ; }
|
||||
boo
|
||||
fi
|
||||
|
||||
fCMD=${CMD/ push / push -f }
|
||||
echo -n "trying '$fCMD' ... "
|
||||
$fCMD >/dev/null 2>&1 && { yay ; exit ; }
|
||||
boo
|
||||
|
||||
exit 1
|
||||
|
||||
else
|
||||
|
||||
yay
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
[[ ${PIPESTATUS[1]} == 1 ]] && echo "Sorry! Failed to push current branch."
|
39
buildroot/share/git/ghtp
Executable file
39
buildroot/share/git/ghtp
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# ghtp (GitHub Transport Protocol)
|
||||
#
|
||||
# Set all remotes in the current repo to HTTPS or SSH connection.
|
||||
# Useful when switching environments, using public wifi, etc.
|
||||
#
|
||||
# Optionally, specify a particular remote to change.
|
||||
#
|
||||
|
||||
GH_SSH="git@github\.com:"
|
||||
GH_HTTPS="https:\/\/github\.com\/"
|
||||
|
||||
case "$1" in
|
||||
-[Hh]) TYPE=HTTPS ; MATCH="git@" ; REPLACE="$GH_SSH/$GH_HTTPS" ;;
|
||||
-[Ss]) TYPE=SSH ; MATCH="https:" ; REPLACE="$GH_HTTPS/$GH_SSH" ;;
|
||||
*)
|
||||
echo "Usage: `basename $0` -h | -s" 1>&2
|
||||
echo -e " \e[0;92m-h\e[0m to switch to HTTPS" 1>&2
|
||||
echo -e " \e[0;92m-s\e[0m to switch to SSH" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
AWK=$(which gawk || which awk)
|
||||
|
||||
# Match all or specified remotes of the other type
|
||||
REGEX="\t$MATCH" ; [[ $# > 1 ]] && REGEX="^$2$REGEX"
|
||||
|
||||
REMOTES=$(git remote -v | egrep "$REGEX" | "$AWK" '{print $1 " " $2}' | sort -u | sed "s/$REPLACE/")
|
||||
|
||||
[[ -z $REMOTES ]] && { echo "Nothing to do." ; exit ; }
|
||||
|
||||
# Update a remote for each results pair
|
||||
echo "$REMOTES" | xargs -n2 git remote set-url
|
||||
|
||||
echo -n "Remotes set to $TYPE: "
|
||||
echo "$REMOTES" | "$AWK" '{printf "%s ", $1}'
|
||||
echo
|
36
buildroot/share/git/mfadd
Executable file
36
buildroot/share/git/mfadd
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfadd user[:branch] [copyname]
|
||||
#
|
||||
# Add a remote and fetch it. Optionally copy a branch.
|
||||
#
|
||||
# Examples:
|
||||
# mfadd thefork
|
||||
# mfadd thefork:patch-1
|
||||
# mfadd thefork:patch-1 the_patch_12345
|
||||
#
|
||||
|
||||
[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` user[:branch] [copyname]" 1>&2 ; exit 1; }
|
||||
|
||||
# If a colon or slash is included, split the parts
|
||||
if [[ $1 =~ ":" || $1 =~ "/" ]]; then
|
||||
[[ $1 =~ ":" ]] && IFS=':' || IFS="/"
|
||||
read -a DATA <<< "$1"
|
||||
USER=${DATA[0]}
|
||||
BRANCH=${DATA[1]}
|
||||
NAME=${2:-$BRANCH}
|
||||
else
|
||||
USER=$1
|
||||
fi
|
||||
|
||||
MFINFO=$(mfinfo) || exit 1
|
||||
IFS=' ' read -a INFO <<< "$MFINFO"
|
||||
REPO=${INFO[2]}
|
||||
|
||||
set -e
|
||||
|
||||
echo "Adding and fetching $USER/$REPO..."
|
||||
git remote add "$USER" "git@github.com:$USER/$REPO.git" >/dev/null 2>&1 || echo "Remote exists."
|
||||
git fetch "$USER"
|
||||
|
||||
[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout -b "$NAME" --track "$USER/$BRANCH"
|
32
buildroot/share/git/mfclean
Executable file
32
buildroot/share/git/mfclean
Executable file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfclean
|
||||
#
|
||||
# Prune all your merged branches and any branches whose remotes are gone
|
||||
# Great way to clean up your branches after messing around a lot
|
||||
#
|
||||
|
||||
AWK=$(which gawk || which awk)
|
||||
|
||||
KEEP="RC|RCBugFix|dev|master|bugfix-1|bugfix-2"
|
||||
|
||||
echo "Fetching latest upstream and origin..."
|
||||
git fetch upstream
|
||||
git fetch origin
|
||||
echo
|
||||
|
||||
echo "Pruning Merged Branches..."
|
||||
git branch --merged | egrep -v "^\*|$KEEP" | xargs -n 1 git branch -d
|
||||
echo
|
||||
|
||||
echo "Pruning Remotely-deleted Branches..."
|
||||
git branch -vv | egrep -v "^\*|$KEEP" | grep ': gone]' | "$AWK" '{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; print ""; }'
|
||||
echo
|
173
buildroot/share/git/mfconfig
Executable file
173
buildroot/share/git/mfconfig
Executable file
@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfconfig init source dest
|
||||
# mfconfig manual source dest
|
||||
#
|
||||
# The MarlinFirmware/Configurations layout could be broken up into branches,
|
||||
# but this makes management more complicated and requires more commits to
|
||||
# perform the same operation, so this uses a single branch with subfolders.
|
||||
#
|
||||
# init - Initialize the repo with a base commit and changes:
|
||||
# - Source will be an 'import' branch containing all current configs.
|
||||
# - Create an empty 'BASE' branch from 'init-repo'.
|
||||
# - Add Marlin config files, but reset all to defaults.
|
||||
# - Commit this so changes will be clear in following commits.
|
||||
# - Add changed Marlin config files and commit.
|
||||
#
|
||||
# manual - Manually import changes from the Marlin repo
|
||||
# - Replace 'default' configs with those from the Marlin repo.
|
||||
# - Wait for manual propagation to the rest of the configs.
|
||||
# - Run init with the given 'source' and 'dest'
|
||||
#
|
||||
|
||||
REPOHOME="`dirname ~/Projects/Maker/Firmware/.`"
|
||||
MARLINREPO="$REPOHOME/MarlinFirmware"
|
||||
CONFIGREPO="$REPOHOME/Configurations"
|
||||
|
||||
CEXA=config/examples
|
||||
CDEF=config/default
|
||||
BC=Configuration.h
|
||||
AC=Configuration_adv.h
|
||||
|
||||
COMMIT_STEPS=0
|
||||
|
||||
#cd "$CONFIGREPO" 2>/dev/null || { echo "Can't find Configurations repo!" ; exit 1; }
|
||||
|
||||
ACTION=${1:-init}
|
||||
IMPORT=${2:-"import-2.1.x"}
|
||||
EXPORT=${3:-"bugfix-2.1.x"}
|
||||
|
||||
echo -n "Doing grhh ... " ; grhh ; echo
|
||||
|
||||
if [[ $ACTION == "manual" ]]; then
|
||||
|
||||
#
|
||||
# Copy the latest default configs from MarlinFirmware/Marlin
|
||||
# or one of the import branches here, then use them to construct
|
||||
# a 'BASE' branch with only defaults as a starting point.
|
||||
#
|
||||
|
||||
echo "- Updating '$IMPORT' from Marlin..."
|
||||
|
||||
git checkout $IMPORT || exit
|
||||
|
||||
# Reset from the latest complete state
|
||||
#git reset --hard bugfix-2.1.x
|
||||
|
||||
cp "$MARLINREPO/Marlin/"Configuration*.h "$CDEF/"
|
||||
#git add . && git commit -m "Changes from Marlin ($(date '+%Y-%m-%d %H:%M'))."
|
||||
|
||||
echo "- Fix up the import branch and come back."
|
||||
|
||||
read -p "- Ready to init [y/N] ?" INIT_YES
|
||||
echo
|
||||
|
||||
[[ $INIT_YES == 'Y' || $INIT_YES == 'y' ]] || { echo "Done." ; exit ; }
|
||||
|
||||
ACTION='init'
|
||||
fi
|
||||
|
||||
if [[ $ACTION == "init" ]]; then
|
||||
#
|
||||
# Copy all configs from a source such as MarlinFirmware/Marlin
|
||||
# or one of the import branches here, then use them to construct
|
||||
# a 'BASE' branch with only defaults as a starting point.
|
||||
#
|
||||
|
||||
SED=$(which gsed sed | head -n1)
|
||||
|
||||
echo "- Initializing BASE branch..."
|
||||
|
||||
# Use the import branch as the source
|
||||
git checkout $IMPORT || exit
|
||||
|
||||
# Copy to a temporary location
|
||||
TEMP=$( mktemp -d ) ; cp -R config $TEMP
|
||||
|
||||
# Strip all #error lines
|
||||
IFS=$'\n'; set -f
|
||||
for fn in $( find $TEMP/config -type f -name "Configuration.h" ); do
|
||||
$SED -i~ -e "20,30{/#error/d}" "$fn"
|
||||
rm "$fn~"
|
||||
done
|
||||
unset IFS; set +f
|
||||
|
||||
# Make sure we're not on the 'BASE' branch...
|
||||
git checkout init-repo >/dev/null 2>&1 || exit
|
||||
|
||||
# Create 'BASE' as a copy of 'init-repo' (README, LICENSE, etc.)
|
||||
git branch -D BASE 2>/dev/null
|
||||
git checkout init-repo -b BASE || exit
|
||||
|
||||
# Copy all config files into place
|
||||
echo "- Copying all configs from fresh $IMPORT..."
|
||||
cp -R "$TEMP/config" .
|
||||
|
||||
# Delete anything that's not a Configuration file
|
||||
find config -type f \! -name "Configuration*" -exec rm "{}" \;
|
||||
|
||||
# DEBUG: Commit the original config files for comparison
|
||||
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Commit for comparison" >/dev/null
|
||||
|
||||
# Init Cartesian/SCARA/TPARA configurations to default
|
||||
echo "- Initializing configs to default state..."
|
||||
|
||||
find "$CEXA" -name $BC -print0 \
|
||||
| while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" ; done
|
||||
find "$CEXA" -name $AC -print0 \
|
||||
| while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" ; done
|
||||
|
||||
# DEBUG: Commit the reset for review
|
||||
((COMMIT_STEPS)) && git add . >/dev/null && git commit -m "Reset configs..." >/dev/null
|
||||
|
||||
# Update the %VERSION% in the README.md file
|
||||
VERS=$( echo $EXPORT | $SED 's/release-//' )
|
||||
eval "${SED} -E -i~ -e 's/%VERSION%/$VERS/g' README.md"
|
||||
rm -f README.md~
|
||||
|
||||
# NOT DEBUGGING: Commit the 'BASE', ready for customizations
|
||||
((COMMIT_STEPS)) || git add . >/dev/null && git commit --amend --no-edit >/dev/null
|
||||
|
||||
# Create a new branch from 'BASE' for the final result
|
||||
echo "- Creating '$EXPORT' branch for the result..."
|
||||
git branch -D $EXPORT 2>/dev/null
|
||||
git checkout -b $EXPORT || exit
|
||||
|
||||
# Delete temporary branch
|
||||
git branch -D BASE 2>/dev/null
|
||||
|
||||
echo "- Applying example config customizations..."
|
||||
cp -R "$TEMP/config" .
|
||||
find config -type f \! -name "Configuration*" -exec rm "{}" \;
|
||||
|
||||
addpathlabels() {
|
||||
find config -name "Conf*.h" -print0 | while read -d $'\0' fn ; do
|
||||
fldr=$(dirname "$fn")
|
||||
blank_line=$(awk '/^\s*$/ {print NR; exit}' "$fn")
|
||||
$SED -i~ "${blank_line}i\\\n#define CONFIG_EXAMPLES_DIR \"$fldr\"" "$fn"
|
||||
rm -f "$fn~"
|
||||
done
|
||||
}
|
||||
|
||||
echo "- Adding path labels to all configs..."
|
||||
addpathlabels
|
||||
|
||||
git add . >/dev/null && git commit -m "Examples Customizations" >/dev/null
|
||||
|
||||
echo "- Copying extras from Marlin..."
|
||||
cp -R "$TEMP/config" .
|
||||
|
||||
# Apply labels again!
|
||||
addpathlabels
|
||||
|
||||
git add . >/dev/null && git commit -m "Examples Extras" >/dev/null
|
||||
|
||||
rm -rf $TEMP
|
||||
|
||||
git push -f --set-upstream upstream "$EXPORT"
|
||||
|
||||
else
|
||||
|
||||
echo "Usage: mfconfig init|manual|rebase"
|
||||
|
||||
fi
|
38
buildroot/share/git/mfdoc
Executable file
38
buildroot/share/git/mfdoc
Executable file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfdoc
|
||||
#
|
||||
# Start Jekyll in watch mode to work on Marlin Documentation and preview locally
|
||||
#
|
||||
|
||||
[[ $# == 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[5]}
|
||||
|
||||
[[ $ORG == "MarlinFirmware" && $REPO == "MarlinDocumentation" ]] || { echo "Wrong repository." 1>&2; exit 1; }
|
||||
|
||||
opensite() {
|
||||
URL="http://127.0.0.1:4000/"
|
||||
OPEN=$( which gnome-open xdg-open open | head -n1 )
|
||||
if [ -z "$OPEN" ]; then
|
||||
echo "Can't find a tool to open the URL:"
|
||||
echo $URL
|
||||
else
|
||||
echo "Opening preview site in the browser..."
|
||||
"$OPEN" "$URL"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Previewing MarlinDocumentation..."
|
||||
|
||||
bundle exec jekyll serve --watch --incremental | {
|
||||
while IFS= read -r line
|
||||
do
|
||||
[[ $line =~ "Server running" ]] && opensite
|
||||
echo "$line"
|
||||
done
|
||||
}
|
31
buildroot/share/git/mffp
Executable file
31
buildroot/share/git/mffp
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mffp [1|2] [ref]
|
||||
#
|
||||
# Push the given commit (or HEAD) upstream immediately.
|
||||
# By default: `git push upstream HEAD:bugfix-2.1.x`
|
||||
#
|
||||
|
||||
usage() { echo "usage: `basename $0` [1|2] [ref]" 1>&2 ; }
|
||||
|
||||
[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { usage ; exit 1; }
|
||||
|
||||
if [[ $1 == '1' || $1 == '2' ]]; then
|
||||
MFINFO=$(mfinfo "$1") || exit 1
|
||||
REF=${2:-HEAD}
|
||||
elif [[ $# == 1 ]]; then
|
||||
MFINFO=$(mfinfo) || exit 1
|
||||
REF=${1:-HEAD}
|
||||
else
|
||||
usage ; exit 1
|
||||
fi
|
||||
|
||||
IFS=' ' read -a INFO <<< "$MFINFO"
|
||||
ORG=${INFO[0]}
|
||||
TARG=${INFO[3]}
|
||||
|
||||
if [[ $ORG == "MarlinFirmware" ]]; then
|
||||
git push upstream $REF:$TARG
|
||||
else
|
||||
echo "Not a MarlinFirmware working copy."; exit 1
|
||||
fi
|
46
buildroot/share/git/mfhelp
Executable file
46
buildroot/share/git/mfhelp
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfhelp
|
||||
#
|
||||
|
||||
cat <<THIS
|
||||
Marlin Firmware Commands:
|
||||
|
||||
firstpush ... Push and set-upstream the current branch to 'origin'
|
||||
ghpc ........ Push the current branch to its upstream branch
|
||||
ghtp ........ Set the transfer protocol for all your remotes
|
||||
mfadd ....... Fetch a remote branch from any Marlin fork
|
||||
mfclean ..... Attempt to clean up merged and deleted branches
|
||||
mfdoc ....... Build the website, serve locally, and browse
|
||||
mffp ........ Push new commits directly to MarlinFirmware
|
||||
mfinfo ...... Provide branch information (for the other scripts)
|
||||
mfinit ...... Create an 'upstream' remote for 'MarlinFirmare'
|
||||
mfnew ....... Create a new branch based on 'bugfix-...'
|
||||
mfpr ........ Push the current branch and open the PR form
|
||||
mfpub ....... Build and publish the marlinfw.org website
|
||||
mfqp ........ Commit changes, do an interactive rebase, and push
|
||||
mfrb ........ Interactively rebase the current branch on 'bugfix-...'
|
||||
mftest ...... Run a platform test locally with PlatformIO
|
||||
mfup ........ Fetch the latest 'upstream' and rebase on it
|
||||
|
||||
Enter [command] --help for more information.
|
||||
|
||||
Build / Test Commands:
|
||||
|
||||
mftest ............... Run a platform test locally with PlatformIO
|
||||
build_all_examples ... Build all configurations of a branch, stop on error
|
||||
|
||||
Modify Configuration.h / Configuration_adv.h:
|
||||
|
||||
opt_add .............. Add a configuration option (to the top of Configuration.h)
|
||||
opt_disable .......... Disable a configuration option (modifies )
|
||||
opt_enable ........... Enable a configuration option
|
||||
opt_set .............. Set the value of a configuration option
|
||||
use_example_configs .. Download configs from a remote branch on GitHub
|
||||
|
||||
Modify pins files:
|
||||
|
||||
pins_set ............. Set the value of a pin in a pins file
|
||||
pinsformat.js ........ Node.js script to format pins files
|
||||
|
||||
THIS
|
66
buildroot/share/git/mfinfo
Executable file
66
buildroot/share/git/mfinfo
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfinfo
|
||||
#
|
||||
# Print the following info about the working copy:
|
||||
#
|
||||
# - Remote (upstream) Org name (MarlinFirmware)
|
||||
# - Remote (origin) Org name (your Github username)
|
||||
# - Repo Name (Marlin, MarlinDocumentation)
|
||||
# - PR Target branch (e.g., bugfix-2.1.x)
|
||||
# - Branch Arg (the branch argument or current branch)
|
||||
# - Current Branch
|
||||
#
|
||||
# Example output
|
||||
# > mfinfo -q ongoing
|
||||
# MarlinFirmware john.doe Marlin bugfix-2.1.x ongoing bugfix-2.1.x -q
|
||||
#
|
||||
|
||||
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; }
|
||||
|
||||
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/')
|
||||
[[ $ORG == MarlinFirmware ]] || { echo "`basename $0`: Not a Marlin repository." 1>&2 ; exit 1; }
|
||||
|
||||
FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
|
||||
|
||||
# Defaults if no arguments given
|
||||
BRANCH=$CURR
|
||||
MORE=""
|
||||
INDEX=2
|
||||
|
||||
# Loop through arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
# Get an arg and maybe a val to go with it
|
||||
opt="$1" ; shift ; val="$1"
|
||||
|
||||
# Split up an arg containing =
|
||||
IFS='=' read -a PARTS <<<"$opt"
|
||||
[[ "${PARTS[1]}" != "" ]] && { EQUALS=1 ; opt="${PARTS[0]}" ; val="${PARTS[1]}" ; }
|
||||
|
||||
if [[ "$val" =~ ^-{1,2}.* || ! "$opt" =~ ^-{1,2}.* ]]; then
|
||||
val=""
|
||||
fi
|
||||
|
||||
case "$opt" in
|
||||
-*|--*) MORE=" $MORE$opt" ; ((EQUALS)) && MORE="$MORE=$val" ;;
|
||||
1|2) INDEX=$opt ;;
|
||||
*) BRANCH="$opt" ;;
|
||||
esac
|
||||
|
||||
done
|
||||
|
||||
case "$REPO" in
|
||||
Marlin ) TARG=bugfix-2.1.x ; ((INDEX == 1)) && TARG=bugfix-1.1.x ; [[ $BRANCH =~ ^[12]$ ]] && USAGE=1 ;;
|
||||
Configurations ) TARG=import-2.1.x ;;
|
||||
MarlinDocumentation ) TARG=master ;;
|
||||
AutoBuildMarlin ) TARG=master ;;
|
||||
esac
|
||||
|
||||
[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1 ; }
|
||||
|
||||
echo "$ORG $FORK $REPO $TARG $BRANCH $CURR$MORE"
|
17
buildroot/share/git/mfinit
Executable file
17
buildroot/share/git/mfinit
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfinit
|
||||
#
|
||||
# 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; }
|
||||
|
||||
echo "Adding 'upstream' remote for convenience."
|
||||
git remote add upstream "git@github.com:MarlinFirmware/$REPO.git"
|
||||
git fetch upstream
|
32
buildroot/share/git/mfnew
Executable file
32
buildroot/share/git/mfnew
Executable file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfnew
|
||||
#
|
||||
# Create a new branch from the default target with the given name
|
||||
#
|
||||
|
||||
usage() { echo "usage: `basename $0` [1|2] [name]" 1>&2 ; }
|
||||
|
||||
[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { usage; exit 1; }
|
||||
|
||||
MFINFO=$(mfinfo "$@") || exit 1
|
||||
IFS=' ' read -a INFO <<< "$MFINFO"
|
||||
TARG=${INFO[3]}
|
||||
BRANCH=pr_for_$TARG-$(date +"%G-%m-%d_%H.%M.%S")
|
||||
|
||||
# BRANCH can be given as the last argument
|
||||
case "$#" in
|
||||
1 ) case "$1" in
|
||||
1|2) ;;
|
||||
*) BRANCH=$1 ;;
|
||||
esac
|
||||
;;
|
||||
2 ) case "$1" in
|
||||
1|2) BRANCH=$2 ;;
|
||||
*) usage ; exit 1 ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
git fetch upstream
|
||||
git checkout --no-track upstream/$TARG -b $BRANCH
|
37
buildroot/share/git/mfpr
Executable file
37
buildroot/share/git/mfpr
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfpr [1|2]
|
||||
#
|
||||
# Make a PR targeted to MarlinFirmware/[repo]
|
||||
#
|
||||
|
||||
[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` [1|2] [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]}
|
||||
|
||||
[[ $BRANCH == $TARG ]] && { echo "Can't create a PR from the PR Target ($BRANCH). Make a copy first." 1>&2 ; exit 1; }
|
||||
|
||||
[[ $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
|
||||
|
||||
OPEN=$( which gnome-open xdg-open open | head -n1 )
|
||||
URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
|
||||
|
||||
if [ -z "$OPEN" ]; then
|
||||
echo "Can't find a tool to open the URL:"
|
||||
echo $URL
|
||||
else
|
||||
echo "Opening a New PR Form..."
|
||||
"$OPEN" "$URL"
|
||||
fi
|
||||
|
||||
[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
|
80
buildroot/share/git/mfprep
Executable file
80
buildroot/share/git/mfprep
Executable file
@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfprep tag1 [tag2]
|
||||
#
|
||||
# Find commits in bugfix-2.1.x that are not yet in 2.1.x.
|
||||
#
|
||||
# Specify a version tag to start from, and optional version tag to end at.
|
||||
# For bugfix-2.1.x the tag will be prefixed by dev- to distinguish it from the version tag,
|
||||
# so at every release be sure to create a dev- tag and publish it to origin.
|
||||
#
|
||||
|
||||
SED=$(which gsed sed | head -n1)
|
||||
SELF=`basename "$0"`
|
||||
DRYRUN=0
|
||||
|
||||
[[ $# < 1 || $# > 2 ]] && { echo "Usage $SELF tag1 [tag2]" ; exit 1 ; }
|
||||
|
||||
TAG1=$1
|
||||
TAG2=${2:-"HEAD"}
|
||||
|
||||
DEST=2.1.x
|
||||
|
||||
# Validate that the required tags exist
|
||||
|
||||
MTAG=`git tag | grep -e "^dev-$TAG1\$"`
|
||||
[[ -n "$MTAG" ]] || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
|
||||
MTAG=`git tag | grep -e "^$TAG1\$"`
|
||||
[[ -n "$MTAG" ]] || { echo "Can't find tag $TAG1" ; exit 1 ; }
|
||||
|
||||
# Generate log of recent commits for bugfix-2.1.x and DEST
|
||||
|
||||
TMPDIR=`mktemp -d`
|
||||
LOGB="$TMPDIR/log-bf.txt"
|
||||
LOG2="$TMPDIR/log-2x.txt"
|
||||
TMPF="$TMPDIR/tmp.txt"
|
||||
SCRF="$TMPDIR/update-$DEST.sh"
|
||||
|
||||
git checkout bugfix-2.1.x
|
||||
git log --pretty="[%h] %s" dev-$TAG1..$TAG2 | grep -v '\[cron\]' | $SED '1!G;h;$!d' >"$LOGB"
|
||||
|
||||
git checkout $DEST
|
||||
git log --pretty="[%h] %s" $TAG1..$TAG2 | $SED '1!G;h;$!d' >"$LOG2" || { echo "Can't find tag dev-$TAG1" ; exit 1 ; }
|
||||
|
||||
# Go through commit text from DEST removing all matches from the bugfix log
|
||||
|
||||
cat "$LOG2" | while read line; do
|
||||
if [[ $line =~ \(((#[0-9]{5}),* *)((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?((#[0-9]{5}),* *)?\)$ ]]; then
|
||||
PATT=""
|
||||
for i in ${!BASH_REMATCH[@]}; do
|
||||
if ((i > 0 && (i % 2 == 0))); then
|
||||
if [[ -n "${BASH_REMATCH[i]}" ]]; then
|
||||
[[ -n "$PATT" ]] && PATT="$PATT|"
|
||||
PATT="$PATT${BASH_REMATCH[i]}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
#echo "... $PATT"
|
||||
[[ -n "$PATT" ]] && { grep -vE "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
|
||||
else
|
||||
PATT=$( $SED -E 's/^\[[0-9a-f]{10}\]( . )?(.+)$/\2/' <<<"$line" )
|
||||
[[ -n "$PATT" ]] && { grep -v "$PATT" "$LOGB" >"$TMPF" ; cp "$TMPF" "$LOGB" ; }
|
||||
fi
|
||||
done
|
||||
|
||||
# Convert remaining commits into git commands
|
||||
|
||||
echo -e "#!/usr/bin/env bash\nset -e\ngit checkout ${DEST}\n" >"$TMPF"
|
||||
cat "$LOGB" | while read line; do
|
||||
if [[ $line =~ ^\[([0-9a-f]{10})\]\ *(.*)$ ]]; then
|
||||
CID=${BASH_REMATCH[1]}
|
||||
REST=${BASH_REMATCH[2]}
|
||||
echo "git cherry-pick $CID ;# $REST" >>"$TMPF"
|
||||
else
|
||||
echo ";# $line" >>"$TMPF"
|
||||
fi
|
||||
done
|
||||
mv "$TMPF" "$SCRF"
|
||||
chmod +x "$SCRF"
|
||||
|
||||
((DRYRUN)) && rm -r "$TMPDIR" || open "$TMPDIR"
|
138
buildroot/share/git/mfpub
Executable file
138
buildroot/share/git/mfpub
Executable file
@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfpub
|
||||
#
|
||||
# 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'.
|
||||
#
|
||||
|
||||
[[ $# < 2 && $1 != "-h" && $1 != "--help" ]] || { 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]}
|
||||
CURR=${INFO[5]}
|
||||
|
||||
if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
|
||||
echo "Wrong repository."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ $BRANCH == "gh-pages" ]]; then
|
||||
echo "Can't build from 'gh-pages.' Only the Jekyll branches (based on 'master')."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Check out the named branch (or stay in current)
|
||||
|
||||
if [[ $BRANCH != $CURR ]]; then
|
||||
echo "Stashing any changes to files..."
|
||||
[[ $(git stash) != "No local "* ]] && HAS_STASH=1
|
||||
git checkout $BRANCH
|
||||
fi
|
||||
|
||||
COMMIT=$( git log --format="%H" -n 1 )
|
||||
|
||||
# Clean out changes and other junk in the branch
|
||||
git clean -d -f
|
||||
|
||||
opensite() {
|
||||
URL="$1"
|
||||
OPEN=$( which gnome-open xdg-open open | head -n1 )
|
||||
if [ -z "$OPEN" ]; then
|
||||
echo "Can't find a tool to open the URL:"
|
||||
echo $URL
|
||||
else
|
||||
echo "Opening the site in the browser..."
|
||||
"$OPEN" "$URL"
|
||||
fi
|
||||
}
|
||||
|
||||
# Push 'master' to the fork and make a proper PR...
|
||||
if [[ $BRANCH == $TARG ]]; then
|
||||
|
||||
# Don't lose upstream changes!
|
||||
git fetch upstream
|
||||
|
||||
# Rebase onto latest master
|
||||
if git rebase upstream/$TARG; then
|
||||
|
||||
# Allow working directly with the main fork
|
||||
echo
|
||||
echo -n "Pushing to origin/$TARG... "
|
||||
git push origin HEAD:$TARG
|
||||
|
||||
echo
|
||||
echo -n "Pushing to upstream/$TARG... "
|
||||
git push upstream HEAD:$TARG
|
||||
|
||||
else
|
||||
|
||||
echo "Merge conflicts? Stopping here."
|
||||
exit
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
if [ -z "$(git branch -vv | grep ^\* | grep \\\[origin)" ]; then
|
||||
firstpush
|
||||
else
|
||||
echo
|
||||
echo -n "Pushing to origin/$BRANCH... "
|
||||
git push -f origin
|
||||
fi
|
||||
|
||||
opensite "https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
|
||||
|
||||
fi
|
||||
|
||||
# Uncomment to compress the final html files
|
||||
# mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
|
||||
# bundle install
|
||||
|
||||
echo
|
||||
echo "Generating MarlinDocumentation..."
|
||||
|
||||
rm -rf build
|
||||
|
||||
# build the site statically and proof it
|
||||
bundle exec jekyll build --profile --trace --no-watch
|
||||
bundle exec htmlproofer ./build --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 build/ ${TMPFOLDER}/
|
||||
|
||||
# Clean out changes and other junk in the branch
|
||||
git reset --hard
|
||||
git clean -d -f
|
||||
|
||||
# Copy built-site into the gh-pages branch
|
||||
git checkout gh-pages || { echo "Something went wrong!"; exit 1; }
|
||||
rsync -av ${TMPFOLDER}/ ./
|
||||
|
||||
# Commit and push the new live site directly
|
||||
git add --all
|
||||
git commit --message "Built from ${COMMIT}"
|
||||
git push -f origin
|
||||
git push -f upstream | {
|
||||
while IFS= read -r line
|
||||
do
|
||||
[[ $line =~ "gh-pages -> gh-pages" ]] && opensite "https://marlinfw.org/"
|
||||
echo "$line"
|
||||
done
|
||||
}
|
||||
|
||||
# remove the temporary folder
|
||||
rm -rf ${TMPFOLDER}
|
||||
|
||||
# Go back to the branch we started from
|
||||
git checkout $CURR && [[ $HAS_STASH == 1 ]] && git stash pop
|
31
buildroot/share/git/mfqp
Executable file
31
buildroot/share/git/mfqp
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfqp [1|2]
|
||||
#
|
||||
# - git add .
|
||||
# - git commit --amend
|
||||
# - git push -f
|
||||
#
|
||||
|
||||
MFINFO=$(mfinfo "$@") || exit 1
|
||||
IFS=' ' read -a INFO <<< "$MFINFO"
|
||||
REPO=${INFO[2]}
|
||||
TARG=${INFO[3]}
|
||||
CURR=${INFO[5]}
|
||||
|
||||
IND=6
|
||||
while [ $IND -lt ${#INFO[@]} ]; do
|
||||
ARG=${INFO[$IND]}
|
||||
case "$ARG" in
|
||||
-f|--force ) FORCE=1 ;;
|
||||
-h|--help ) USAGE=1 ;;
|
||||
* ) USAGE=1 ; echo "unknown option: $ARG" ;;
|
||||
esac
|
||||
let IND+=1
|
||||
done
|
||||
|
||||
[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2]" 1>&2 ; exit 1 ; }
|
||||
|
||||
[[ $FORCE != 1 && $CURR == $TARG && $REPO != "MarlinDocumentation" ]] && { echo "Don't alter the PR Target branch."; exit 1 ; }
|
||||
|
||||
git add . && git commit --amend && git push -f
|
27
buildroot/share/git/mfrb
Executable file
27
buildroot/share/git/mfrb
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfrb
|
||||
#
|
||||
# Do "git rebase -i" against the repo's "target" branch
|
||||
#
|
||||
|
||||
MFINFO=$(mfinfo "$@") || exit 1
|
||||
IFS=' ' read -a INFO <<< "$MFINFO"
|
||||
TARG=${INFO[3]}
|
||||
CURR=${INFO[5]}
|
||||
|
||||
IND=6
|
||||
while [ $IND -lt ${#INFO[@]} ]; do
|
||||
ARG=${INFO[$IND]}
|
||||
case "$ARG" in
|
||||
-q|--quick ) QUICK=1 ;;
|
||||
-h|--help ) USAGE=1 ;;
|
||||
* ) USAGE=1 ; echo "unknown option: $ARG" ;;
|
||||
esac
|
||||
let IND+=1
|
||||
done
|
||||
|
||||
[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2]" 1>&2 ; exit 1 ; }
|
||||
|
||||
[[ $QUICK ]] || git fetch upstream
|
||||
git rebase upstream/$TARG && git rebase -i upstream/$TARG
|
48
buildroot/share/git/mfup
Executable file
48
buildroot/share/git/mfup
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# mfup
|
||||
#
|
||||
# - 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'
|
||||
#
|
||||
|
||||
[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` [1|2] [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]}
|
||||
CURR=${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
|
||||
|
||||
if [[ $BRANCH != $TARG ]]; then
|
||||
echo ; echo "Rebasing $BRANCH on $TARG..."
|
||||
if [[ $BRANCH == $CURR ]] || git checkout $BRANCH; then
|
||||
if git rebase upstream/$TARG; then
|
||||
git push -f
|
||||
else
|
||||
echo "Looks like merge conflicts. Stopping here."
|
||||
exit
|
||||
fi
|
||||
else
|
||||
echo "No such branch!"
|
||||
fi
|
||||
else
|
||||
git reset --hard upstream/$TARG
|
||||
fi
|
||||
|
||||
echo
|
||||
[[ $BRANCH != $CURR ]] && git checkout $CURR
|
||||
|
||||
[[ $HAS_STASH == 1 ]] && git stash pop
|
Reference in New Issue
Block a user