Update git helper scripts

2.0.x
Scott Lahteine 7 years ago
parent e0a6ee8da5
commit ca21367dde

@ -7,11 +7,15 @@
# - Remote (upstream) Org name (MarlinFirmware)
# - Remote (origin) Org name (your Github username)
# - Repo Name (Marlin, MarlinDev, MarlinDocumentation)
# - PR Target branch (bugfix-2.0.x, dev, or master)
# - PR Target branch (bugfix-1.1.x, bugfix-2.0.x, or master)
# - Branch Arg (the branch argument or current branch)
# - Current Branch
#
usage() {
echo "Usage: `basename $0` [1|2] [branch]" 1>&2
}
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; }
@ -23,17 +27,29 @@ 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; }
case "$REPO" in
Marlin ) TARG=bugfix-2.0.x ;;
MarlinDev ) TARG=dev ;;
Marlin ) TARG=bugfix-1.1.x ;
[[ $# > 0 ]] && [[ $1 == 2 ]] && TARG=bugfix-2.0.x
;;
MarlinDocumentation ) TARG=master ;;
esac
FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
# BRANCH can be given as the last argument
case "$#" in
0 ) BRANCH=$CURR ;;
1 ) BRANCH=$1 ;;
* ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
1 )
case "$1" in
1|2) BRANCH=$CURR ;;
*) BRANCH=$1 ;;
esac
;;
2 )
case "$1" in
1|2) BRANCH=$2 ;;
*) usage ; exit 1 ;;
esac
;;
esac
echo "$ORG $FORK $REPO $TARG $BRANCH $CURR"

@ -5,15 +5,29 @@
# Create a new branch from the default target with the given name
#
[[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
usage() {
echo "Usage: `basename $0` [1|2] [name]" 1>&2
}
MFINFO=$(mfinfo) || exit 1
[[ $# < 3 ]] || { 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
0 ) BRANCH=pr_for_$TARG-$(date +"%G-%m-%d_%H.%M.%S") ;;
1 ) BRANCH=$1 ;;
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

@ -5,24 +5,23 @@
# Add all changed files, commit as "patch", do `mfrb` and `git push -f`
#
[[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
[[ $# < 2 ]] || { echo "Usage: `basename $0` [1|2]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo) || exit 1
MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO"
REPO=${INFO[2]}
TARG=${INFO[3]}
BRANCH=${INFO[5]}
CURR=${INFO[5]}
git add .
git commit -m "patch"
if [[ $BRANCH == $TARG ]]; then
if [[ $CURR == $TARG ]]; then
if [[ $REPO == "MarlinDocumentation" ]]; then
git rebase -i HEAD~2
git rebase -i HEAD~2 && git push -f
else
echo "Don't alter the PR Target branch."; exit 1
fi
else
mfrb
git push -f
mfrb "$@" && git push -f
fi

@ -2,18 +2,18 @@
#
# mfrb
#
# Do "git rebase -i" against the "target" branch (RCBugFix or dev)
# Do "git rebase -i" against the "target" branch (bugfix-1.1.x, bugfix-2.0.x, or master)
#
[[ $# == 0 ]] || { echo "Usage: `basename $0`" 1>&2 ; exit 1; }
[[ $# < 2 ]] || { echo "Usage: `basename $0` [1|2]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo) || exit 1
MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO"
TARG=${INFO[3]}
BRANCH=${INFO[5]}
CURR=${INFO[5]}
# If the branch isn't currently the PR target
if [[ $TARG != $BRANCH ]]; then
if [[ $TARG != $CURR ]]; then
git fetch upstream
git rebase upstream/$TARG && git rebase -i upstream/$TARG
fi

@ -5,10 +5,9 @@
# - 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'
# -
#
[[ $# < 2 ]] || { echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1; }
[[ $# < 3 ]] || { echo "Usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; }
MFINFO=$(mfinfo "$@") || exit 1
IFS=' ' read -a INFO <<< "$MFINFO"
@ -17,7 +16,7 @@ FORK=${INFO[1]}
REPO=${INFO[2]}
TARG=${INFO[3]}
BRANCH=${INFO[4]}
OLDBRANCH=${INFO[5]}
CURR=${INFO[5]}
set -e
@ -27,23 +26,14 @@ set -e
echo "Fetching upstream ($ORG/$REPO)..."
git fetch upstream
echo ; echo "Bringing $TARG up to date..."
if [[ ! $(git checkout -q $TARG) ]]; then
git reset --hard upstream/$TARG
git push -f origin
else
git checkout upstream/$TARG -b $TARG
git push --set-upstream origin $TARG
fi
if [[ $BRANCH != $TARG ]]; then
echo ; echo "Rebasing $BRANCH on $TARG..."
if git checkout $BRANCH; then
echo
if git rebase $TARG; then
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
echo "Looks like merge conflicts. Stopping here."
exit
fi
else
echo "No such branch!"
@ -51,6 +41,6 @@ if [[ $BRANCH != $TARG ]]; then
fi
echo
[[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
[[ $BRANCH != $CURR ]] && git checkout $CURR
[[ $HAS_STASH == 1 ]] && git stash pop

Loading…
Cancel
Save