-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit_clone_lite.sh
executable file
·55 lines (44 loc) · 1.03 KB
/
git_clone_lite.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
# [repository-url] [subdirectory]
# Clones a specific subdirectory from a git repository with depth 1 and single branch
git-clone-lite() {
depth= d=1 # Clone depth
single= s= # Single branch
branch= b= # Branch to clone
output= o= # Output directory name
eval "$(ally)"
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
usage
fi
repo_url=$1 subdir=$2
if [ -z "$output" ]; then
output=$(basename "$repo_url")
fi
# Set up git clone arguments
args=()
if [ -n "$depth" ]; then
args+=(--depth "$depth")
fi
if [ -n "$single" ]; then
args+=(--single-branch)
fi
if [ -n "$branch" ]; then
args+=(--branch "$branch")
fi
if [ -n "$subdir" ]; then
args+=(--no-checkout)
fi
# Clone the repository
git clone "${args[@]}" "$repo_url" "$output"
# Sparse checkout for a specific subdirectory
if [ -n "$subdir" ]; then
cd "$output"
git sparse-checkout init --cone
git sparse-checkout set "$subdir"
git checkout
fi
}
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
git-clone-lite "$@"
fi
# version: 0.1.0