You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
901 B
Plaintext
37 lines
901 B
Plaintext
8 years ago
|
#!/usr/bin/env bash
|
||
|
#
|
||
5 years ago
|
# mfadd user[:branch] [copyname]
|
||
8 years ago
|
#
|
||
7 years ago
|
# Add a remote and fetch it. Optionally copy a branch.
|
||
|
#
|
||
5 years ago
|
# Examples:
|
||
|
# mfadd thefork
|
||
|
# mfadd thefork:patch-1
|
||
|
# mfadd thefork:patch-1 the_patch_12345
|
||
8 years ago
|
#
|
||
|
|
||
5 years ago
|
[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` user[:branch] [copyname]" 1>&2 ; exit 1; }
|
||
8 years ago
|
|
||
5 years ago
|
# If a colon or slash is included, split the parts
|
||
|
if [[ $1 =~ ":" || $1 =~ "/" ]]; then
|
||
|
[[ $1 =~ ":" ]] && IFS=':' || IFS="/"
|
||
|
read -a DATA <<< "$1"
|
||
7 years ago
|
USER=${DATA[0]}
|
||
|
BRANCH=${DATA[1]}
|
||
5 years ago
|
NAME=${2:-$BRANCH}
|
||
7 years ago
|
else
|
||
|
USER=$1
|
||
|
fi
|
||
8 years ago
|
|
||
8 years ago
|
MFINFO=$(mfinfo) || exit 1
|
||
|
IFS=' ' read -a INFO <<< "$MFINFO"
|
||
8 years ago
|
REPO=${INFO[2]}
|
||
|
|
||
|
set -e
|
||
|
|
||
|
echo "Adding and fetching $USER..."
|
||
7 years ago
|
git remote add "$USER" "git@github.com:$USER/$REPO.git" >/dev/null 2>&1 || echo "Remote exists."
|
||
8 years ago
|
git fetch "$USER"
|
||
7 years ago
|
|
||
5 years ago
|
[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout -b "$NAME" --track "$USER/$BRANCH"
|