1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-23 20:18:52 +00:00
MarlinFirmware/buildroot/share/git/mfinfo
2017-07-03 01:13:07 -05:00

40 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# mfinfo
#
# Provide the following info about the working directory:
#
# - Remote (upstream) Org name (MarlinFirmware)
# - Remote (origin) Org name (your Github username)
# - Repo Name (Marlin, MarlinDev, MarlinDocumentation)
# - PR Target branch (bugfix-1.1.x, dev, or master)
# - Branch Arg (the branch argument or current branch)
# - Current Branch
#
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; }
case "$REPO" in
Marlin ) TARG=bugfix-1.1.x ;;
MarlinDev ) TARG=dev ;;
MarlinDocumentation ) TARG=master ;;
esac
FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
case "$#" in
0 ) BRANCH=$CURR ;;
1 ) BRANCH=$1 ;;
* ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
esac
echo "$ORG $FORK $REPO $TARG $BRANCH $CURR"