-
Notifications
You must be signed in to change notification settings - Fork 6
/
repo.sh
62 lines (55 loc) · 1.31 KB
/
repo.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
56
57
58
59
60
61
#!/bin/bash
# Function to initialize sparse checkout, excluding the data/raw folder
initial_clone() {
REPO_URL=$1
TARGET_DIR=$2
# Clone the repository with sparse checkout enabled
git clone --filter=blob:none --no-checkout "$REPO_URL" "$TARGET_DIR"
cd "$TARGET_DIR"
# Enable sparse checkout and exclude the data/raw folder
git sparse-checkout init --cone
git sparse-checkout set 'src'
git checkout
}
# Function to download specific subfolder from data/raw
download_subfolder() {
SUBFOLDER=$1
git sparse-checkout add $SUBFOLDER
git checkout
}
# Function to clean up downloaded subfolder after processing
cleanup_subfolder() {
SUBFOLDER=$1
escaped_path=$(echo $SUBFOLDER | sed 's/\//\\\//g')
sed -i /$escaped_path/d .git/info/sparse-checkout
rm -rf $SUBFOLDER
git sparse-checkout reapply
}
# Main script logic
case $1 in
clone)
if [ $# -ne 3 ]; then
echo "Usage: $0 clone <repo_url> <target_dir>"
exit 1
fi
initial_clone $2 $3
;;
download)
if [ $# -ne 2 ]; then
echo "Usage: $0 download <subfolder>"
exit 1
fi
download_subfolder $2
;;
cleanup)
if [ $# -ne 2 ]; then
echo "Usage: $0 cleanup <subfolder>"
exit 1
fi
cleanup_subfolder $2
;;
*)
echo "Usage: $0 {clone|download|cleanup}"
exit 1
;;
esac