]> git.phdru.name Git - git-scripts.git/blobdiff - sparse-clone
Feat(submodules/remove): Add option `-c`
[git-scripts.git] / sparse-clone
index 5bbaa6b982ec2f9af1c2a31b60d7a46e96449439..2c37c7741e0eac4ab8ebdc7a2cd06837ac32df59 100755 (executable)
@@ -2,15 +2,30 @@
 # Adapted from https://stackoverflow.com/a/13738951/7976758
 set -e
 
-rurl="$1"
-localdir="$2"
-shift 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"
+shift
+
+test -z "$branch" && branch=master
+test -z "$local_repo" && local_repo="`basename \"$origin\" .git`"
 
-mkdir -p "$localdir"
-cd "$localdir"
+mkdir -p "$local_repo"
+cd "$local_repo"
 
 git init
-git remote add origin "$rurl"
+git remote add origin "$origin"
 
 git config core.sparseCheckout true
 
@@ -19,4 +34,4 @@ for arg; do
   echo "$arg" >> .git/info/sparse-checkout
 done
 
-exec git pull origin master
+exec git pull origin $branch