1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-12-12 21:41:34 +00:00
MarlinFirmware/buildroot/share/git/mfinfo

61 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
#
# mfinfo
#
2017-07-03 01:43:57 +00:00
# Provide the following info about the working directory:
#
# - Remote (upstream) Org name (MarlinFirmware)
# - Remote (origin) Org name (your Github username)
# - Repo Name (Marlin, MarlinDocumentation)
2019-12-16 09:33:17 +00:00
# - PR Target branch (bugfix-1.1.x, bugfix-2.0.x, dev-2.1.x, etc.)
2017-07-03 01:43:57 +00:00
# - Branch Arg (the branch argument or current branch)
# - Current Branch
#
2017-07-03 01:43:57 +00: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; }
2017-07-03 01:43:57 +00: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; }
ORG=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
2017-07-03 01:43:57 +00:00
[[ $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
INDEX=1
while [[ $# -gt 0 ]]; do
opt="$1" ; shift ; val="$1"
IFS='=' read -a PARTS <<<"$opt"
2019-08-24 07:10:50 +00:00
[[ "${PARTS[1]}" != "" ]] && { 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
2019-08-24 07:10:50 +00:00
-*|--*) MORE="$MORE$opt " ; [[ $EQUALS == 1 ]] && MORE="$MORE=$val" ;;
2019-12-16 09:33:17 +00:00
1|2|3) INDEX=$opt ;;
*) BRANCH="$opt" ;;
esac
done
case "$REPO" in
2019-12-16 09:33:17 +00:00
Marlin ) TARG=bugfix-1.1.x ; [[ $INDEX == 2 ]] && TARG=bugfix-2.0.x ; [[ $INDEX == 3 ]] && TARG=dev-2.1.x ;;
MarlinDocumentation ) TARG=master ;;
esac
2019-12-16 09:33:17 +00:00
[[ $BRANCH =~ ^[123]$ ]] && USAGE=1
2019-12-16 09:33:17 +00:00
[[ $USAGE == 1 ]] && { echo "usage: `basename $0` [1|2|3] [branch]" 1>&2 ; exit 1 ; }
echo "$ORG $FORK $REPO $TARG $BRANCH $CURR $MORE"