3 . "$(dirname "$0")/testlib.sh"
6 contents_oid=$(calc_oid "$contents")
9 reponame="$(basename "$0" ".sh")"
11 begin_test "init for fetch tests"
15 setup_remote_repo "$reponame"
17 clone_repo "$reponame" repo
19 git lfs track "*.dat" 2>&1 | tee track.log
20 grep "Tracking \"\*.dat\"" track.log
23 printf "%s" "$contents" > a.dat
25 git add .gitattributes
26 git commit -m "add a.dat" 2>&1 | tee commit.log
27 grep "master (root-commit)" commit.log
28 grep "2 files changed" commit.log
29 grep "create mode 100644 a.dat" commit.log
30 grep "create mode 100644 .gitattributes" commit.log
32 [ "a" = "$(cat a.dat)" ]
34 assert_local_object "$contents_oid" 1
36 refute_server_object "$reponame" "$contents_oid"
38 git push origin master 2>&1 | tee push.log
39 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
40 grep "master -> master" push.log
42 assert_server_object "$reponame" "$contents_oid"
44 # Add a file in a different branch
45 git checkout -b newbranch
46 printf "%s" "$b" > b.dat
48 git commit -m "add b.dat"
49 assert_local_object "$b_oid" 1
51 git push origin newbranch
52 assert_server_object "$reponame" "$b_oid"
54 # These clones are used for subsequent tests
55 clone_repo "$reponame" clone
56 git clone --shared "$TRASHDIR/clone" "$TRASHDIR/shared"
64 rm -rf .git/lfs/objects
66 git lfs fetch 2>&1 | grep "Downloading LFS objects: 100% (1/1), 1 B"
67 assert_local_object "$contents_oid" 1
69 git lfs fsck 2>&1 | tee fsck.log
70 grep "Git LFS fsck OK" fsck.log
74 begin_test "fetch (shared repository)"
78 rm -rf .git/lfs/objects
80 git lfs fetch 2>&1 | tee fetch.log
81 ! grep "Could not scan" fetch.log
82 assert_local_object "$contents_oid" 1
84 git lfs fsck 2>&1 | tee fsck.log
85 grep "Git LFS fsck OK" fsck.log
89 begin_test "fetch with remote"
93 rm -rf .git/lfs/objects
95 git lfs fetch origin 2>&1 | grep "Downloading LFS objects: 100% (1/1), 1 B"
96 assert_local_object "$contents_oid" 1
97 refute_local_object "$b_oid" 1
99 git lfs fsck 2>&1 | tee fsck.log
100 grep "Git LFS fsck OK" fsck.log
104 begin_test "fetch with remote and branches"
109 git checkout newbranch
112 rm -rf .git/lfs/objects
114 git lfs fetch origin master newbranch
115 assert_local_object "$contents_oid" 1
116 assert_local_object "$b_oid" 1
118 git lfs fsck 2>&1 | tee fsck.log
119 grep "Git LFS fsck OK" fsck.log
123 begin_test "fetch with master commit sha1"
127 rm -rf .git/lfs/objects
129 master_sha1=$(git rev-parse master)
130 git lfs fetch origin "$master_sha1"
131 assert_local_object "$contents_oid" 1
132 refute_local_object "$b_oid" 1
134 git lfs fsck 2>&1 | tee fsck.log
135 grep "Git LFS fsck OK" fsck.log
139 begin_test "fetch with newbranch commit sha1"
143 rm -rf .git/lfs/objects
145 newbranch_sha1=$(git rev-parse newbranch)
146 git lfs fetch origin "$newbranch_sha1"
147 assert_local_object "$contents_oid" 1
148 assert_local_object "$b_oid" 1
150 git lfs fsck 2>&1 | tee fsck.log
151 grep "Git LFS fsck OK" fsck.log
155 begin_test "fetch with include filters in gitconfig"
159 rm -rf .git/lfs/objects
161 git config "lfs.fetchinclude" "a*"
162 git lfs fetch origin master newbranch
163 assert_local_object "$contents_oid" 1
164 refute_local_object "$b_oid"
166 git lfs fsck 2>&1 | tee fsck.log
167 grep "Git LFS fsck OK" fsck.log
171 begin_test "fetch with exclude filters in gitconfig"
176 git config --unset "lfs.fetchinclude"
177 rm -rf .git/lfs/objects
179 git config "lfs.fetchexclude" "a*"
180 git lfs fetch origin master newbranch
181 refute_local_object "$contents_oid"
182 assert_local_object "$b_oid" 1
184 git lfs fsck 2>&1 | tee fsck.log
185 grep "Git LFS fsck OK" fsck.log
189 begin_test "fetch with include/exclude filters in gitconfig"
193 rm -rf .git/lfs/objects
194 git config --unset "lfs.fetchexclude"
196 git config "lfs.fetchinclude" "a*,b*"
197 git config "lfs.fetchexclude" "c*,d*"
198 git lfs fetch origin master newbranch
199 assert_local_object "$contents_oid" 1
200 assert_local_object "$b_oid" 1
202 rm -rf .git/lfs/objects
203 git config "lfs.fetchinclude" "c*,d*"
204 git config "lfs.fetchexclude" "a*,b*"
205 git lfs fetch origin master newbranch
206 refute_local_object "$contents_oid"
207 refute_local_object "$b_oid"
211 begin_test "fetch with include filter in cli"
215 git config --unset "lfs.fetchinclude"
216 git config --unset "lfs.fetchexclude"
217 rm -rf .git/lfs/objects
219 git lfs fetch --include="a*" origin master newbranch
220 assert_local_object "$contents_oid" 1
221 refute_local_object "$b_oid"
225 begin_test "fetch with exclude filter in cli"
229 rm -rf .git/lfs/objects
230 git lfs fetch --exclude="a*" origin master newbranch
231 refute_local_object "$contents_oid"
232 assert_local_object "$b_oid" 1
236 begin_test "fetch with include/exclude filters in cli"
240 rm -rf .git/lfs/objects
241 git lfs fetch -I "a*,b*" -X "c*,d*" origin master newbranch
242 assert_local_object "$contents_oid" 1
243 assert_local_object "$b_oid" 1
245 rm -rf .git/lfs/objects
246 git lfs fetch --include="c*,d*" --exclude="a*,b*" origin master newbranch
247 refute_local_object "$contents_oid"
248 refute_local_object "$b_oid"
252 begin_test "fetch with include filter overriding exclude filter"
256 rm -rf .git/lfs/objects
257 git config lfs.fetchexclude "b*"
258 git lfs fetch -I "b.dat" -X "" origin master newbranch
259 assert_local_object "$b_oid" "1"
263 begin_test "fetch with missing object"
267 git config --unset lfs.fetchexclude
268 rm -rf .git/lfs/objects
270 delete_server_object "$reponame" "$b_oid"
271 refute_server_object "$reponame" "$b_oid"
273 # should return non-zero, but should also download all the other valid files too
275 git lfs fetch origin master newbranch
278 [ "$fetch_exit" != "0" ]
279 assert_local_object "$contents_oid" 1
280 refute_local_object "$b_oid"
284 begin_test "fetch-all"
289 setup_remote_repo "$reponame"
291 clone_repo "$reponame" "$reponame"
293 git lfs track "*.dat" 2>&1 | tee track.log
294 grep "Tracking \"\*.dat\"" track.log
297 # generate content we'll use
298 for ((a=0; a < NUMFILES ; a++))
300 content[$a]="filecontent$a"
301 oid[$a]=$(calc_oid "${content[$a]}")
306 \"CommitDate\":\"$(get_date -180d)\",
308 {\"Filename\":\"file1.dat\",\"Size\":${#content[0]}, \"Data\":\"${content[0]}\"},
309 {\"Filename\":\"file2.dat\",\"Size\":${#content[1]}, \"Data\":\"${content[1]}\"}]
312 \"NewBranch\":\"branch1\",
313 \"CommitDate\":\"$(get_date -140d)\",
315 {\"Filename\":\"file3.dat\",\"Size\":${#content[2]}, \"Data\":\"${content[2]}\"}]
318 \"ParentBranches\":[\"master\"],
319 \"CommitDate\":\"$(get_date -100d)\",
321 {\"Filename\":\"file1.dat\",\"Size\":${#content[3]}, \"Data\":\"${content[3]}\"}]
324 \"NewBranch\":\"remote_branch_only\",
325 \"CommitDate\":\"$(get_date -80d)\",
327 {\"Filename\":\"file2.dat\",\"Size\":${#content[4]}, \"Data\":\"${content[4]}\"}]
330 \"ParentBranches\":[\"master\"],
331 \"CommitDate\":\"$(get_date -75d)\",
333 {\"Filename\":\"file4.dat\",\"Size\":${#content[5]}, \"Data\":\"${content[5]}\"}]
336 \"NewBranch\":\"tag_only\",
338 \"CommitDate\":\"$(get_date -70d)\",
340 {\"Filename\":\"file4.dat\",\"Size\":${#content[6]}, \"Data\":\"${content[6]}\"}]
343 \"ParentBranches\":[\"master\"],
344 \"CommitDate\":\"$(get_date -60d)\",
346 {\"Filename\":\"file1.dat\",\"Size\":${#content[7]}, \"Data\":\"${content[7]}\"}]
349 \"NewBranch\":\"branch3\",
350 \"CommitDate\":\"$(get_date -50d)\",
352 {\"Filename\":\"file4.dat\",\"Size\":${#content[8]}, \"Data\":\"${content[8]}\"}]
355 \"CommitDate\":\"$(get_date -40d)\",
356 \"ParentBranches\":[\"master\"],
358 {\"Filename\":\"file1.dat\",\"Size\":${#content[9]}, \"Data\":\"${content[9]}\"},
359 {\"Filename\":\"file2.dat\",\"Size\":${#content[10]}, \"Data\":\"${content[10]}\"}]
362 \"ParentBranches\":[\"master\"],
363 \"CommitDate\":\"$(get_date -30d)\",
365 {\"Filename\":\"file4.dat\",\"Size\":${#content[11]}, \"Data\":\"${content[11]}\"}]
367 ]" | lfstest-testutils addcommits
369 git push origin master
370 git push origin branch1
371 git push origin branch3
372 git push origin remote_branch_only
373 git push origin tag_only
374 for ((a=0; a < NUMFILES ; a++))
376 assert_server_object "$reponame" "${oid[$a]}"
379 # delete remote_branch_only and make sure that objects are downloaded even
380 # though not checked out to a local branch (full backup always)
381 git branch -D remote_branch_only
383 # delete tag_only to make sure objects are downloaded when only reachable from tag
384 git branch -D tag_only
386 rm -rf .git/lfs/objects
388 git lfs fetch --all origin
389 for ((a=0; a < NUMFILES ; a++))
391 assert_local_object "${oid[$a]}" "${#content[$a]}"
394 # Make a bare clone of the repository
396 git clone --bare "$GITSERVER/$reponame" "$reponame-bare"
399 # Preform the same assertion as above, on the same data
400 git lfs fetch --all origin
401 for ((a=0; a < NUMFILES ; a++)); do
402 assert_local_object "${oid[$a]}" "${#content[$a]}"
407 begin_test "fetch: outside git repository"
410 git lfs fetch 2>&1 > fetch.log
414 if [ "$res" = "0" ]; then
415 echo "Passes because $GIT_LFS_TEST_DIR is unset."
419 grep "Not in a git repository" fetch.log
423 begin_test "fetch with no origin remote"
427 reponame="fetch-no-remote"
428 setup_remote_repo "$reponame"
430 clone_repo "$reponame" no-remote-clone
432 clone_repo "$reponame" no-remote-repo
434 git lfs track "*.dat" 2>&1 | tee track.log
435 grep "Tracking \"\*.dat\"" track.log
438 contents_oid=$(calc_oid "$contents")
440 printf "%s" "$contents" > a.dat
442 git add .gitattributes
443 git commit -m "add a.dat" 2>&1 | tee commit.log
444 grep "master (root-commit)" commit.log
445 grep "2 files changed" commit.log
446 grep "create mode 100644 a.dat" commit.log
447 grep "create mode 100644 .gitattributes" commit.log
449 [ "a" = "$(cat a.dat)" ]
451 assert_local_object "$contents_oid" 1
453 refute_server_object "$reponame" "$contents_oid"
455 git push origin master 2>&1 | tee push.log
456 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
457 grep "master -> master" push.log
460 # change to the clone's working directory
461 cd ../no-remote-clone
465 assert_local_object "$contents_oid" 1
467 # now checkout detached HEAD so we're not tracking anything on remote
468 git checkout --detach
473 # rename remote from 'origin' to 'something'
474 git remote rename origin something
476 # fetch should still pick this remote as in the case of no tracked remote,
477 # and no origin, but only 1 remote, should pick the only one as default
479 assert_local_object "$contents_oid" 1
483 begin_test "fetch --prune"
487 reponame="fetch_prune"
488 setup_remote_repo "remote_$reponame"
490 clone_repo "remote_$reponame" "clone_$reponame"
492 git lfs track "*.dat" 2>&1 | tee track.log
493 grep "Tracking \"\*.dat\"" track.log
495 content_head="HEAD content"
496 content_commit2="Content for commit 2 (prune)"
497 content_commit1="Content for commit 1 (prune)"
498 oid_head=$(calc_oid "$content_head")
499 oid_commit2=$(calc_oid "$content_commit2")
500 oid_commit1=$(calc_oid "$content_commit1")
504 \"CommitDate\":\"$(get_date -50d)\",
506 {\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}]
509 \"CommitDate\":\"$(get_date -35d)\",
511 {\"Filename\":\"file.dat\",\"Size\":${#content_commit2}, \"Data\":\"$content_commit2\"}]
514 \"CommitDate\":\"$(get_date -25d)\",
516 {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}]
518 ]" | lfstest-testutils addcommits
520 # push all so no unpushed reason to not prune
521 git push origin master
523 # set no recents so max ability to prune
524 git config lfs.fetchrecentrefsdays 0
525 git config lfs.fetchrecentcommitsdays 0
527 # delete HEAD object to prove that we still download something
528 # also prune at the same time which will remove anything other than HEAD
529 delete_local_object "$oid_head"
530 git lfs fetch --prune
531 assert_local_object "$oid_head" "${#content_head}"
532 refute_local_object "$oid_commit1"
533 refute_local_object "$oid_commit2"
537 begin_test "fetch raw remote url"
543 git lfs install --local --skip-smudge
545 git remote add origin "$GITSERVER/$reponame"
546 git pull origin master
548 # LFS object not downloaded, pointer in working directory
549 refute_local_object "$contents_oid"
550 grep "$content_oid" a.dat
552 git lfs fetch "$GITSERVER/$reponame"
554 # LFS object downloaded, pointer still in working directory
555 assert_local_object "$contents_oid" 1
556 grep "$content_oid" a.dat
560 begin_test "fetch with invalid remote"
564 git lfs fetch not-a-remote 2>&1 | tee fetch.log
565 grep "Invalid remote name" fetch.log