Blame | Last modification | View Log | RSS feed
#!/usr/bin/env bash## mfadd## Add a remote and fetch it. Optionally copy a branch.## Example: mfadd thinkyhead:patch-1 copy_of_patch-1#[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` (user | ref copyname)" 1>&2 ; exit 1; }# If a colon is included, split the partsif [[ $1 =~ ":" ]]; thenIFS=':' read -a DATA <<< "$1"USER=${DATA[0]}BRANCH=${DATA[1]}NAME=$2elseUSER=$1fiMFINFO=$(mfinfo) || exit 1IFS=' ' read -a INFO <<< "$MFINFO"REPO=${INFO[2]}set -eecho "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 $USER/$BRANCH -b $NAME