From 1af05797d7e571cf619f5672fb9b2fb9fc5442d2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 1 Feb 2020 00:27:11 -0600 Subject: [PATCH] Improve mfadd helper script - Use the original branch name if none is supplied - Set the remote tracking to the source - Accept User/Branch or User:Branch syntax --- buildroot/share/git/mfadd | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/buildroot/share/git/mfadd b/buildroot/share/git/mfadd index 92b2e0063e..30be1ec0f7 100755 --- a/buildroot/share/git/mfadd +++ b/buildroot/share/git/mfadd @@ -1,20 +1,24 @@ #!/usr/bin/env bash # -# mfadd (user|ref) [copyname] +# mfadd user[:branch] [copyname] # # Add a remote and fetch it. Optionally copy a branch. # -# Example: mfadd myfork:patch-1 copy_of_patch-1 +# 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|ref) [copyname]" 1>&2 ; exit 1; } +[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` user[:branch] [copyname]" 1>&2 ; exit 1; } -# If a colon is included, split the parts -if [[ $1 =~ ":" ]]; then - IFS=':' read -a DATA <<< "$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 + NAME=${2:-$BRANCH} else USER=$1 fi @@ -29,4 +33,4 @@ 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 $USER/$BRANCH -b $NAME +[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout -b "$NAME" --track "$USER/$BRANCH"