1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-12-05 02:19:14 +00:00
MarlinFirmware/buildroot/share/git/mfadd

37 lines
901 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
#
# mfadd user[:branch] [copyname]
#
2018-03-02 02:41:01 +00:00
# Add a remote and fetch it. Optionally copy a branch.
#
# Examples:
# mfadd thefork
# mfadd thefork:patch-1
# mfadd thefork:patch-1 the_patch_12345
#
[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` user[:branch] [copyname]" 1>&2 ; exit 1; }
# If a colon or slash is included, split the parts
if [[ $1 =~ ":" || $1 =~ "/" ]]; then
[[ $1 =~ ":" ]] && IFS=':' || IFS="/"
read -a DATA <<< "$1"
2018-03-02 02:41:01 +00:00
USER=${DATA[0]}
BRANCH=${DATA[1]}
NAME=${2:-$BRANCH}
2018-03-02 02:41:01 +00:00
else
USER=$1
fi
2017-07-03 01:43:57 +00:00
MFINFO=$(mfinfo) || exit 1
IFS=' ' read -a INFO <<< "$MFINFO"
REPO=${INFO[2]}
set -e
echo "Adding and fetching $USER..."
2018-03-02 02:41:01 +00:00
git remote add "$USER" "git@github.com:$USER/$REPO.git" >/dev/null 2>&1 || echo "Remote exists."
2017-07-03 01:43:57 +00:00
git fetch "$USER"
2018-03-02 02:41:01 +00:00
[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout -b "$NAME" --track "$USER/$BRANCH"