| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | reponame_src="$(basename "$0" ".sh")-src" |
| 6 | reponame_dst="$(basename "$0" ".sh")-dst" |
| 7 | |
| 8 | begin_test "fetch lfs-tracked file despite no remote" |
| 9 | ( |
| 10 | set -e |
| 11 | |
| 12 | # First, a repo with an lfs-tracked file we can fetch from |
| 13 | setup_remote_repo_with_file "$reponame_src" "test_file.dat" |
| 14 | |
| 15 | # Grab the rev for `git archive` later |
| 16 | echo $(pwd) |
| 17 | rev=$(git rev-parse HEAD) |
| 18 | cd .. |
| 19 | |
| 20 | # Initialize a bare repo we can fetch into |
| 21 | mkdir $reponame_dst |
| 22 | cd $reponame_dst |
| 23 | git init . --bare |
| 24 | echo $(pwd) |
| 25 | git fetch "$GITSERVER/$reponame_src" refs/heads/main:refs/heads/main |
| 26 | git archive $rev -o archive.out |
| 27 | |
| 28 | # Verify archive contains our file |
| 29 | [ 1 -eq "$(tar -tvf archive.out test_file.dat | wc -l)" ] |
| 30 | ) |
| 31 | end_test |
| 32 | |
| 33 | reponame_src_A="$(basename "$0" ".sh")-src-A" |
| 34 | reponame_src_B="$(basename "$0" ".sh")-src-B" |
| 35 | reponame_dst_2="$(basename "$0" ".sh")-dst-2" |
| 36 | begin_test "fallback ignored when remote present" |
| 37 | ( |
| 38 | set -e |
| 39 | |
| 40 | # Initialize 2 repos with different files |
| 41 | setup_remote_repo_with_file "$reponame_src_A" "test_file_A.dat" |
| 42 | rev=$(git rev-parse HEAD) |
| 43 | cd .. |
| 44 | setup_remote_repo_with_file "$reponame_src_B" "test_file_B.dat" |
| 45 | cd .. |
| 46 | |
| 47 | mkdir $reponame_dst_2 |
| 48 | cd $reponame_dst_2 |
| 49 | git init . --bare |
| 50 | echo $(pwd) |
| 51 | # This part is subtle |
| 52 | # Add repo A as a remote and fetch from it |
| 53 | # But then fetch from repo B. This points FETCH_HEAD to repo B |
| 54 | # We're testing that git-lfs will ignore FETCH_HEAD, since FETCH_HEAD is |
| 55 | # a fallback, only used when no remote is set |
| 56 | git remote add origin "$GITSERVER/$reponame_src_A" |
| 57 | git fetch |
| 58 | git fetch "$GITSERVER/$reponame_src_B" refs/heads/main:refs/heads/main |
| 59 | git archive $rev -o archive.out |
| 60 | |
| 61 | # Verify archive contains file from second repo, but not first repo |
| 62 | [ 1 -eq "$(tar -tvf archive.out test_file_A.dat | wc -l)" ] |
| 63 | [ 0 -eq "$(tar -tvf archive.out test_file_B.dat | wc -l)" ] |
| 64 | ) |
| 65 | end_test |
| 66 |