2016-04-19 06:18:35 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# mfinfo
|
|
|
|
#
|
2021-11-03 13:02:21 +01:00
|
|
|
# Print the following info about the working copy:
|
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)
|
2022-06-04 06:50:20 +02:00
|
|
|
# - PR Target branch (e.g., bugfix-2.1.x)
|
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
|
|
|
#
|
2021-11-03 13:02:21 +01:00
|
|
|
# Example output
|
|
|
|
# > mfinfo -q ongoing
|
2022-06-04 06:50:20 +02:00
|
|
|
# MarlinFirmware john.doe Marlin bugfix-2.1.x ongoing bugfix-2.1.x -q
|
2021-11-03 13:02:21 +01:00
|
|
|
#
|
2016-04-19 06:18:35 +02: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
|
2021-11-03 13:02:21 +01:00
|
|
|
MORE=""
|
|
|
|
INDEX=2
|
2019-01-23 07:03:20 +01:00
|
|
|
|
2021-11-03 13:02:21 +01:00
|
|
|
# Loop through arguments
|
2019-01-23 07:03:20 +01:00
|
|
|
while [[ $# -gt 0 ]]; do
|
2021-11-03 13:02:21 +01:00
|
|
|
# Get an arg and maybe a val to go with it
|
2019-01-23 07:03:20 +01:00
|
|
|
opt="$1" ; shift ; val="$1"
|
|
|
|
|
2021-11-03 13:02:21 +01:00
|
|
|
# Split up an arg containing =
|
2019-01-23 07:03:20 +01:00
|
|
|
IFS='=' read -a PARTS <<<"$opt"
|
2019-08-24 09:10:50 +02:00
|
|
|
[[ "${PARTS[1]}" != "" ]] && { EQUALS=1 ; opt="${PARTS[0]}" ; val="${PARTS[1]}" ; }
|
2019-01-23 07:03:20 +01:00
|
|
|
|
|
|
|
if [[ "$val" =~ ^-{1,2}.* || ! "$opt" =~ ^-{1,2}.* ]]; then
|
|
|
|
val=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$opt" in
|
2021-11-03 13:02:21 +01:00
|
|
|
-*|--*) MORE=" $MORE$opt" ; ((EQUALS)) && MORE="$MORE=$val" ;;
|
|
|
|
1|2) INDEX=$opt ;;
|
2019-01-23 07:03:20 +01:00
|
|
|
*) BRANCH="$opt" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
case "$REPO" in
|
2022-06-04 06:50:20 +02:00
|
|
|
Marlin ) TARG=bugfix-2.1.x ; ((INDEX == 1)) && TARG=bugfix-1.1.x ; [[ $BRANCH =~ ^[12]$ ]] && USAGE=1 ;;
|
2020-09-28 10:57:09 +02:00
|
|
|
Configurations ) TARG=import-2.0.x ;;
|
2019-01-23 07:03:20 +01:00
|
|
|
MarlinDocumentation ) TARG=master ;;
|
2021-11-02 07:28:00 +01:00
|
|
|
AutoBuildMarlin ) TARG=master ;;
|
2016-04-19 06:18:35 +02:00
|
|
|
esac
|
|
|
|
|
2021-11-03 13:02:21 +01:00
|
|
|
[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1 ; }
|
2019-02-02 21:03:10 +01:00
|
|
|
|
2021-11-03 13:02:21 +01:00
|
|
|
echo "$ORG $FORK $REPO $TARG $BRANCH $CURR$MORE"
|