]> git.phdru.name Git - git-scripts.git/blob - sparse-clone
Feat(submodules/remove): Add option `-c`
[git-scripts.git] / sparse-clone
1 #! /bin/sh
2 # Adapted from https://stackoverflow.com/a/13738951/7976758
3 set -e
4
5 while getopts b:l: opt; do
6    case $opt in
7       b ) branch="$OPTARG" ;;
8       l ) local_repo="$OPTARG" ;;
9    esac
10 done
11 shift `expr $OPTIND - 1`
12
13 if [ -z "$2" ]; then
14    echo "Usage: $0 [-b branch] [-l local] origin patterns..." >&2
15    exit 1
16 fi
17
18 origin="$1"
19 shift
20
21 test -z "$branch" && branch=master
22 test -z "$local_repo" && local_repo="`basename \"$origin\" .git`"
23
24 mkdir -p "$local_repo"
25 cd "$local_repo"
26
27 git init
28 git remote add origin "$origin"
29
30 git config core.sparseCheckout true
31
32 # Loops over remaining args
33 for arg; do
34   echo "$arg" >> .git/info/sparse-checkout
35 done
36
37 exec git pull origin $branch