| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | assert_same_inode() { |
| 6 | local repo1=$1 |
| 7 | local repo2=$2 |
| 8 | local oid=$3 |
| 9 | |
| 10 | if ! uname -s | grep -qE 'CYGWIN|MSYS|MINGW'; then |
| 11 | cfg1=$(cd "$repo1"; git lfs env | grep LocalMediaDir) |
| 12 | f1="${cfg1:14}/${oid:0:2}/${oid:2:2}/$oid" |
| 13 | inode1=$(ls -i $f1 | cut -f1 -d\ ) |
| 14 | |
| 15 | cfg2=$(cd "$repo2"; git lfs env | grep LocalMediaDir) |
| 16 | f2="${cfg2:14}/${oid:0:2}/${oid:2:2}/$oid" |
| 17 | inode2=$(ls -i $f2 | cut -f1 -d\ ) |
| 18 | |
| 19 | [ "$inode1" == "$inode2" ] |
| 20 | fi |
| 21 | } |
| 22 | |
| 23 | begin_test "clone with reference" |
| 24 | ( |
| 25 | set -e |
| 26 | |
| 27 | reponame="$(basename "$0" ".sh")" |
| 28 | setup_remote_repo "$reponame" |
| 29 | |
| 30 | ref_repo=clone_reference_repo |
| 31 | ref_repo_dir=$TRASHDIR/$ref_repo |
| 32 | clone_repo "$reponame" "$ref_repo" |
| 33 | git lfs track "*.dat" |
| 34 | contents="a" |
| 35 | oid=$(calc_oid "$contents") |
| 36 | |
| 37 | printf "%s" "$contents" > a.dat |
| 38 | git add a.dat |
| 39 | git add .gitattributes |
| 40 | git commit -m "add a.dat" 2>&1 |
| 41 | git push origin main |
| 42 | |
| 43 | delete_server_object "$reponame" "$oid" |
| 44 | |
| 45 | repo=test_repo |
| 46 | repo_dir=$TRASHDIR/$repo |
| 47 | git clone --reference "$ref_repo_dir/.git" \ |
| 48 | "$GITSERVER/$reponame" "$repo_dir" |
| 49 | |
| 50 | cd "$TRASHDIR/$repo" |
| 51 | |
| 52 | assert_pointer "main" "a.dat" "$oid" 1 |
| 53 | assert_same_inode "$repo_dir" "$ref_repo_dir" "$oid" |
| 54 | ) |
| 55 | end_test |
| 56 | |
| 57 | begin_test "fetch from clone reference" |
| 58 | ( |
| 59 | set -e |
| 60 | |
| 61 | reponame="$(basename "$0" ".sh")2" |
| 62 | setup_remote_repo "$reponame" |
| 63 | |
| 64 | ref_repo=clone_reference_repo2 |
| 65 | ref_repo_dir=$TRASHDIR/$ref_repo |
| 66 | clone_repo "$reponame" "$ref_repo" |
| 67 | |
| 68 | repo=test_repo2 |
| 69 | repo_dir=$TRASHDIR/$repo |
| 70 | git clone --reference "$ref_repo_dir/.git" \ |
| 71 | "$GITSERVER/$reponame" "$repo_dir" 2> clone.log |
| 72 | |
| 73 | cd "$ref_repo_dir" |
| 74 | git lfs track "*.dat" |
| 75 | contents="a" |
| 76 | oid=$(calc_oid "$contents") |
| 77 | |
| 78 | printf "%s" "$contents" > a.dat |
| 79 | git add a.dat |
| 80 | git add .gitattributes |
| 81 | git commit -m "add a.dat" 2>&1 |
| 82 | git push origin main |
| 83 | |
| 84 | delete_server_object "$reponame" "$oid" |
| 85 | |
| 86 | cd "$repo_dir" |
| 87 | GIT_LFS_SKIP_SMUDGE=1 git pull origin main |
| 88 | git lfs pull |
| 89 | |
| 90 | assert_pointer "main" "a.dat" "$oid" 1 |
| 91 | assert_same_inode "$TRASHDIR/$repo" "$TRASHDIR/$ref_repo" "$oid" |
| 92 | ) |
| 93 | end_test |