diff options
author | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
---|---|---|
committer | Georgiy Bondarenko <69736697+nehilo@users.noreply.github.com> | 2021-03-04 20:54:23 +0300 |
commit | e8701195e66f2d27ffe17fb514eae8173795aaf7 (patch) | |
tree | 9f519c4abf6556b9ae7190a6210d87ead1dfadde /buildroot/share/git/mfadd | |
download | kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.tar.xz kp3s-lgvl-e8701195e66f2d27ffe17fb514eae8173795aaf7.zip |
Initial commit
Diffstat (limited to 'buildroot/share/git/mfadd')
-rw-r--r-- | buildroot/share/git/mfadd | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/buildroot/share/git/mfadd b/buildroot/share/git/mfadd new file mode 100644 index 0000000..30be1ec --- /dev/null +++ b/buildroot/share/git/mfadd @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# +# mfadd user[:branch] [copyname] +# +# 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" + USER=${DATA[0]} + BRANCH=${DATA[1]} + NAME=${2:-$BRANCH} +else + USER=$1 +fi + +MFINFO=$(mfinfo) || exit 1 +IFS=' ' read -a INFO <<< "$MFINFO" +REPO=${INFO[2]} + +set -e + +echo "Adding and fetching $USER..." +git remote add "$USER" "git@github.com:$USER/$REPO.git" >/dev/null 2>&1 || echo "Remote exists." +git fetch "$USER" + +[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout -b "$NAME" --track "$USER/$BRANCH" |