-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpull
More file actions
executable file
·133 lines (115 loc) · 2.81 KB
/
pull
File metadata and controls
executable file
·133 lines (115 loc) · 2.81 KB
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
124
125
126
127
128
129
130
131
132
133
#!/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"
OUTPUT="$VENDOR/$1"
# Masking
if [ -f "$OUTPUT.mask" ]
then
while read -r path
do
log "Masking $1: $path"
rm -rf "$4/$1/${path:?}"
done < "$OUTPUT.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 $OUTPUT"
rm -rf "$OUTPUT"
mkdir -p "$(dirname "$OUTPUT")"
mv "$4/$1" "$OUTPUT"
}
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)"
PULL_LOCATION="${2-}"
if [ -n "$PULL_LOCATION" ]
then
URL="$PULL_LOCATION"
else
URL="$(echo "$LINE" | cut -d ' ' -f 2)"
fi
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