forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht-pull.sh
executable file
·261 lines (213 loc) · 6.11 KB
/
t-pull.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "pull"
(
set -e
reponame="$(basename "$0" ".sh")"
setup_remote_repo "$reponame"
clone_repo "$reponame" clone
clone_repo "$reponame" repo
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
contents="a"
contents_oid=$(calc_oid "$contents")
contents2="A"
contents2_oid=$(calc_oid "$contents2")
contents3="dir"
contents3_oid=$(calc_oid "$contents3")
mkdir dir
echo "*.log" > .gitignore
printf "$contents" > a.dat
printf "$contents2" > á.dat
printf "$contents3" > dir/dir.dat
git add .
git commit -m "add files" 2>&1 | tee commit.log
grep "master (root-commit)" commit.log
grep "5 files changed" commit.log
grep "create mode 100644 a.dat" commit.log
grep "create mode 100644 .gitattributes" commit.log
ls -al
[ "a" = "$(cat a.dat)" ]
[ "A" = "$(cat "á.dat")" ]
[ "dir" = "$(cat "dir/dir.dat")" ]
assert_pointer "master" "a.dat" "$contents_oid" 1
assert_pointer "master" "á.dat" "$contents2_oid" 1
assert_pointer "master" "dir/dir.dat" "$contents3_oid" 3
refute_server_object "$reponame" "$contents_oid"
refute_server_object "$reponame" "$contents2_oid"
refute_server_object "$reponame" "$contents33oid"
echo "initial push"
git push origin master 2>&1 | tee push.log
grep "Uploading LFS objects: 100% (3/3), 5 B" push.log
grep "master -> master" push.log
assert_server_object "$reponame" "$contents_oid"
assert_server_object "$reponame" "$contents2_oid"
assert_server_object "$reponame" "$contents3_oid"
# change to the clone's working directory
cd ../clone
echo "normal pull"
git pull 2>&1
[ "a" = "$(cat a.dat)" ]
[ "A" = "$(cat "á.dat")" ]
assert_local_object "$contents_oid" 1
assert_local_object "$contents2_oid" 1
assert_clean_status
echo "lfs pull"
rm -r a.dat á.dat dir # removing files makes the status dirty
rm -rf .git/lfs/objects
git lfs pull 2>&1 | grep "Downloading LFS objects: 100% (3/3), 5 B"
ls -al
[ "a" = "$(cat a.dat)" ]
[ "A" = "$(cat "á.dat")" ]
assert_local_object "$contents_oid" 1
assert_local_object "$contents2_oid" 1
echo "lfs pull with remote"
rm -r a.dat á.dat dir
rm -rf .git/lfs/objects
git lfs pull origin 2>&1 | grep "Downloading LFS objects: 100% (3/3), 5 B"
[ "a" = "$(cat a.dat)" ]
[ "A" = "$(cat "á.dat")" ]
assert_local_object "$contents_oid" 1
assert_local_object "$contents2_oid" 1
assert_clean_status
echo "lfs pull with local storage"
rm a.dat á.dat
git lfs pull
[ "a" = "$(cat a.dat)" ]
[ "A" = "$(cat "á.dat")" ]
assert_clean_status
echo "lfs pull with include/exclude filters in gitconfig"
rm -rf .git/lfs/objects
git config "lfs.fetchinclude" "a*"
git lfs pull
assert_local_object "$contents_oid" 1
assert_clean_status
rm -rf .git/lfs/objects
git config --unset "lfs.fetchinclude"
git config "lfs.fetchexclude" "a*"
git lfs pull
refute_local_object "$contents_oid"
assert_clean_status
echo "lfs pull with include/exclude filters in command line"
git config --unset "lfs.fetchexclude"
rm -rf .git/lfs/objects
git lfs pull --include="a*"
assert_local_object "$contents_oid" 1
assert_clean_status
rm -rf .git/lfs/objects
git lfs pull --exclude="a*"
refute_local_object "$contents_oid"
assert_clean_status
echo "resetting to test status"
git reset --hard
assert_clean_status
echo "lfs pull clean status"
git lfs pull
assert_clean_status
echo "lfs pull with -I"
git lfs pull -I "*.dat"
assert_clean_status
echo "lfs pull in subdir"
cd dir
git lfs pull
assert_clean_status
echo "lfs pull in subdir with -I"
git lfs pull -I "*.dat"
assert_clean_status
)
end_test
begin_test "pull without clean filter"
(
set -e
GIT_LFS_SKIP_SMUDGE=1 git clone $GITSERVER/test-pull no-clean
cd no-clean
git lfs uninstall
git config --list > config.txt
grep "filter.lfs.clean" config.txt && {
echo "clean filter still configured:"
cat config.txt
exit 1
}
contents="a"
contents_oid=$(calc_oid "$contents")
# LFS object not downloaded, pointer in working directory
grep "$contents_oid" a.dat || {
echo "a.dat not $contents_oid"
ls -al
cat a.dat
exit 1
}
assert_local_object "$contents_oid"
git lfs pull | tee pull.txt
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: expected pull to succeed ..."
exit 1
fi
grep "Git LFS is not installed" pull.txt
echo "pulled!"
# LFS object downloaded, pointer unchanged
grep "$contents_oid" a.dat || {
echo "a.dat not $contents_oid"
ls -al
cat a.dat
exit 1
}
assert_local_object "$contents_oid" 1
)
end_test
begin_test "pull with raw remote url"
(
set -e
mkdir raw
cd raw
git init
git lfs install --local --skip-smudge
git remote add origin $GITSERVER/test-pull
git pull origin master
contents="a"
contents_oid=$(calc_oid "$contents")
# LFS object not downloaded, pointer in working directory
refute_local_object "$contents_oid"
grep "$contents_oid" a.dat
git lfs pull "$GITSERVER/test-pull"
echo "pulled!"
# LFS object downloaded and in working directory
assert_local_object "$contents_oid" 1
[ "0" = "$(grep -c "$contents_oid" a.dat)" ]
[ "a" = "$(cat a.dat)" ]
)
end_test
begin_test "pull: with missing object"
(
set -e
# this clone is setup in the first test in this file
cd clone
rm -rf .git/lfs/objects
contents_oid=$(calc_oid "a")
reponame="$(basename "$0" ".sh")"
delete_server_object "$reponame" "$contents_oid"
refute_server_object "$reponame" "$contents_oid"
# should return non-zero, but should also download all the other valid files too
git lfs pull 2>&1 | tee pull.log
pull_exit="${PIPESTATUS[0]}"
[ "$pull_exit" != "0" ]
grep "$contents_oid" pull.log
contents2_oid=$(calc_oid "A")
assert_local_object "$contents2_oid" 1
refute_local_object "$contents_oid"
)
end_test
begin_test "pull: outside git repository"
(
set +e
git lfs pull 2>&1 > pull.log
res=$?
set -e
if [ "$res" = "0" ]; then
echo "Passes because $GIT_LFS_TEST_DIR is unset."
exit 0
fi
[ "$res" = "128" ]
grep "Not in a git repository" pull.log
)
end_test