-
Notifications
You must be signed in to change notification settings - Fork 1
/
pull
executable file
·123 lines (108 loc) · 2.69 KB
/
pull
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh
set -o errexit
set -o nounset
ROOT="$(git rev-parse --show-toplevel)"
DEPENDENCIES="$ROOT/DEPENDENCIES"
VENDOR="$ROOT/vendor"
PATCHES="$ROOT/patches"
fail() {
echo "$1" 1>&2
exit 1
}
log() {
echo "-- $1" 1>&2
}
# $1 = name
# $2 = url
# $3 = version
# $4 = tmp
vendor() {
# Cloning
log "Fetching $2@$3 into $4/$1"
git clone --recurse-submodules --jobs 8 "$2" "$4/$1"
git -C "$4/$1" reset --hard "$3"
# Patching
if [ -d "$PATCHES/$1" ]
then
for patch in "$PATCHES/$1"/*.patch
do
log "Patching $1: $patch"
git -C "$4/$1" apply --3way "$patch"
done
fi
# Pruning
log "Pruning $4/$1"
git -C "$4/$1" submodule foreach "rm -rf .git"
git -C "$4/$1" submodule foreach "rm -rf .gitignore"
git -C "$4/$1" submodule foreach "rm -rf .github"
git -C "$4/$1" submodule foreach "rm -rf .gitmodules"
git -C "$4/$1" submodule foreach "rm -rf .gitattributes"
rm -rf "$4/$1/.git"
rm -rf "$4/$1/.gitignore"
rm -rf "$4/$1/.github"
rm -rf "$4/$1/.gitmodules"
rm -rf "$4/$1/.gitattributes"
# Masking
if [ -f "$VENDOR/$1.mask" ]
then
while read -r path
do
log "Masking $1: $path"
rm -rf "$4/$1/${path:?}"
done < "$VENDOR/$1.mask"
elif [ -f "$4/$1/vendorpull.mask" ]
then
while read -r path
do
log "Masking $1: $path"
rm -rf "$4/$1/${path:?}"
done < "$4/$1/vendorpull.mask"
rm -f "$4/$1/vendorpull.mask"
fi
# Swap
log "Moving $4/$1 to $VENDOR/$1"
rm -rf "$VENDOR/${1:?}"
mkdir -p "$VENDOR"
mv "$4/$1" "$VENDOR/$1"
}
if [ ! -f "$DEPENDENCIES" ]
then
fail "File not found: $DEPENDENCIES"
fi
DEPENDENCY="${1-}"
if [ -n "$DEPENDENCY" ]
then
LINE="$(grep "^$DEPENDENCY " < "$DEPENDENCIES" || true)"
if [ -z "$LINE" ]
then
fail "Unknown dependency: $DEPENDENCY"
fi
NAME="$(echo "$LINE" | cut -d ' ' -f 1)"
URL="$(echo "$LINE" | cut -d ' ' -f 2)"
VERSION="$(echo "$LINE" | cut -d ' ' -f 3)"
if [ -z "$NAME" ] || [ -z "$URL" ] || [ -z "$VERSION" ]
then
fail "Invalid dependency definition: $DEPENDENCY"
fi
TMP="$(mktemp -d -t vendorpull-clone-XXXXX)"
log "Setting up temporary directory at $TMP..."
clean() { rm -rf "$TMP"; }
trap clean EXIT
vendor "$NAME" "$URL" "$VERSION" "$TMP"
else
TMP="$(mktemp -d -t vendorpull-clone-XXXXX)"
log "Setting up temporary directory at $TMP..."
clean() { rm -rf "$TMP"; }
trap clean EXIT
while read -r line
do
NAME="$(echo "$line" | cut -d ' ' -f 1)"
URL="$(echo "$line" | cut -d ' ' -f 2)"
VERSION="$(echo "$line" | cut -d ' ' -f 3)"
if [ -z "$NAME" ] || [ -z "$URL" ] || [ -z "$VERSION" ]
then
fail "Invalid dependency definition"
fi
vendor "$NAME" "$URL" "$VERSION" "$TMP"
done < "$DEPENDENCIES"
fi