2017-04-21 02:27:32 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# mfadd
|
|
|
|
#
|
2018-03-02 02:40:53 +00:00
|
|
|
# Add a remote and fetch it. Optionally copy a branch.
|
|
|
|
#
|
|
|
|
# Example: mfadd thinkyhead:patch-1 copy_of_patch-1
|
2017-04-21 02:27:32 +00:00
|
|
|
#
|
|
|
|
|
2018-03-02 02:40:53 +00:00
|
|
|
[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` (user | ref copyname)" 1>&2 ; exit 1; }
|
2017-04-21 02:27:32 +00:00
|
|
|
|
2018-03-02 02:40:53 +00:00
|
|
|
# If a colon is included, split the parts
|
|
|
|
if [[ $1 =~ ":" ]]; then
|
|
|
|
IFS=':' read -a DATA <<< "$1"
|
|
|
|
USER=${DATA[0]}
|
|
|
|
BRANCH=${DATA[1]}
|
|
|
|
NAME=$2
|
|
|
|
else
|
|
|
|
USER=$1
|
|
|
|
fi
|
2017-04-21 02:27:32 +00:00
|
|
|
|
2017-07-03 01:43:57 +00:00
|
|
|
MFINFO=$(mfinfo) || exit 1
|
|
|
|
IFS=' ' read -a INFO <<< "$MFINFO"
|
2017-04-21 02:27:32 +00:00
|
|
|
REPO=${INFO[2]}
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
echo "Adding and fetching $USER..."
|
2018-03-02 02:40:53 +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:40:53 +00:00
|
|
|
|
|
|
|
[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout $USER/$BRANCH -b $NAME
|