From 3f382a0981cedf0448c973311675aafbc0a3bbf2 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 12 May 2020 15:07:01 +0300 Subject: [PATCH] Feat(sparse-clone): Add options parser Parametrize branch (default is master) and local directory (default is the name of the remote repo). --- sparse-clone | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sparse-clone b/sparse-clone index 0037a86..2c37c77 100755 --- a/sparse-clone +++ b/sparse-clone @@ -2,14 +2,24 @@ # Adapted from https://stackoverflow.com/a/13738951/7976758 set -e -if [ -z "$3" ]; then - echo "Usage: $0 origin local patterns..." >&2 +while getopts b:l: opt; do + case $opt in + b ) branch="$OPTARG" ;; + l ) local_repo="$OPTARG" ;; + esac +done +shift `expr $OPTIND - 1` + +if [ -z "$2" ]; then + echo "Usage: $0 [-b branch] [-l local] origin patterns..." >&2 exit 1 fi origin="$1" -local_repo="$2" -shift 2 +shift + +test -z "$branch" && branch=master +test -z "$local_repo" && local_repo="`basename \"$origin\" .git`" mkdir -p "$local_repo" cd "$local_repo" @@ -24,4 +34,4 @@ for arg; do echo "$arg" >> .git/info/sparse-checkout done -exec git pull origin master +exec git pull origin $branch -- 2.39.2