2016-04-19 06:18:35 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# mfinfo
|
|
|
|
#
|
2017-07-03 03:43:57 +02:00
|
|
|
# Provide the following info about the working directory:
|
2016-04-19 06:18:35 +02:00
|
|
|
#
|
|
|
|
# - Remote (upstream) Org name (MarlinFirmware)
|
|
|
|
# - Remote (origin) Org name (your Github username)
|
2019-01-23 07:03:20 +01:00
|
|
|
# - Repo Name (Marlin, MarlinDocumentation)
|
|
|
|
# - PR Target branch (bugfix-1.1.x, bugfix-2.0.x, etc.)
|
2017-07-03 03:43:57 +02:00
|
|
|
# - Branch Arg (the branch argument or current branch)
|
|
|
|
# - Current Branch
|
2016-04-19 06:18:35 +02:00
|
|
|
#
|
|
|
|
|
2019-01-23 07:03:20 +01:00
|
|
|
# usage() { echo "Usage: `basename $0` [1|2] [branch]" 1>&2 ; }
|
|
|
|
# [[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { usage; exit 1; }
|
2018-03-02 03:41:01 +01:00
|
|
|
|
2017-07-03 03:43:57 +02:00
|
|
|
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; }
|
2016-04-19 06:18:35 +02:00
|
|
|
|
2017-07-03 03:43:57 +02:00
|
|
|
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; }
|
2016-04-19 06:18:35 +02:00
|
|
|
|
|
|
|
ORG=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
|
2017-07-03 03:43:57 +02:00
|
|
|
[[ $ORG == MarlinFirmware ]] || { echo "`basename $0`: Not a Marlin repository." 1>&2 ; exit 1; }
|
2016-04-19 06:18:35 +02:00
|
|
|
|
|
|
|
FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
|
|
|
|
|
2019-01-23 07:03:20 +01:00
|
|
|
# Defaults if no arguments given
|
|
|
|
BRANCH=$CURR
|
|
|
|
INDEX=1
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
opt="$1" ; shift ; val="$1"
|
|
|
|
|
|
|
|
IFS='=' read -a PARTS <<<"$opt"
|
|
|
|
[[ "${PARTS[1]}" != "" ]] && { HAS_EQUALS=1 ; opt="${PARTS[0]}" ; val="${PARTS[1]}" ; }
|
|
|
|
|
|
|
|
GOODVAL=1
|
|
|
|
if [[ "$val" =~ ^-{1,2}.* || ! "$opt" =~ ^-{1,2}.* ]]; then
|
|
|
|
GOODVAL=0
|
|
|
|
val=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$opt" in
|
|
|
|
-*|--*) MORE="$MORE$opt " ; [[ $HAS_EQUALS ]] && MORE="$MORE=$val" ;;
|
|
|
|
1|2) INDEX=$opt ;;
|
|
|
|
*) BRANCH="$opt" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
case "$REPO" in
|
|
|
|
Marlin ) TARG=bugfix-1.1.x ; [[ $INDEX == 2 ]] && TARG=bugfix-2.0.x ;;
|
|
|
|
MarlinDocumentation ) TARG=master ;;
|
2016-04-19 06:18:35 +02:00
|
|
|
esac
|
|
|
|
|
2019-01-23 07:03:20 +01:00
|
|
|
echo "$ORG $FORK $REPO $TARG $BRANCH $CURR $MORE"
|