| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "fetch with good ref" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="fetch-main-branch-required" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" "$reponame" |
| 12 | |
| 13 | git lfs track "*.dat" |
| 14 | echo "a" > a.dat |
| 15 | git add .gitattributes a.dat |
| 16 | git commit -m "add a.dat" |
| 17 | |
| 18 | git push origin main |
| 19 | |
| 20 | # $ echo "a" | shasum -a 256 |
| 21 | oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7" |
| 22 | assert_local_object "$oid" 2 |
| 23 | assert_server_object "$reponame" "$oid" "refs/heads/main" |
| 24 | |
| 25 | rm -rf .git/lfs/objects |
| 26 | git lfs fetch --all |
| 27 | assert_local_object "$oid" 2 |
| 28 | ) |
| 29 | end_test |
| 30 | |
| 31 | begin_test "fetch with tracked ref" |
| 32 | ( |
| 33 | set -e |
| 34 | |
| 35 | reponame="fetch-tracked-branch-required" |
| 36 | setup_remote_repo "$reponame" |
| 37 | clone_repo "$reponame" "$reponame" |
| 38 | |
| 39 | git lfs track "*.dat" |
| 40 | echo "a" > a.dat |
| 41 | git add .gitattributes a.dat |
| 42 | git commit -m "add a.dat" |
| 43 | |
| 44 | git push origin main:tracked |
| 45 | |
| 46 | # $ echo "a" | shasum -a 256 |
| 47 | oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7" |
| 48 | assert_local_object "$oid" 2 |
| 49 | assert_server_object "$reponame" "$oid" "refs/heads/tracked" |
| 50 | |
| 51 | rm -rf .git/lfs/objects |
| 52 | git config push.default upstream |
| 53 | git config branch.main.merge refs/heads/tracked |
| 54 | git lfs fetch --all |
| 55 | assert_local_object "$oid" 2 |
| 56 | ) |
| 57 | end_test |
| 58 | |
| 59 | begin_test "fetch with pushRemote configured" |
| 60 | ( |
| 61 | set -e |
| 62 | |
| 63 | reponame="fetch-tracked-with-push-remote-tracked-branch-required" |
| 64 | setup_remote_repo "$reponame" |
| 65 | clone_repo "$reponame" "$reponame" |
| 66 | |
| 67 | git lfs track "*.dat" |
| 68 | echo "a" > a.dat |
| 69 | git add .gitattributes a.dat |
| 70 | git commit -m "add a.dat" |
| 71 | |
| 72 | git push origin main:tracked |
| 73 | |
| 74 | # $ echo "a" | shasum -a 256 |
| 75 | oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7" |
| 76 | assert_local_object "$oid" 2 |
| 77 | assert_server_object "$reponame" "$oid" "refs/heads/tracked" |
| 78 | |
| 79 | # Configure tracking to "tracked" and set a separate push remote. |
| 80 | # The fetch should send refs/heads/tracked (the tracking ref) to the server, |
| 81 | # not a ref derived from push.default logic using the push remote. |
| 82 | git remote add push-only "$GITSERVER/$reponame" |
| 83 | git config remote.pushDefault push-only |
| 84 | git config branch.main.merge refs/heads/tracked |
| 85 | |
| 86 | rm -rf .git/lfs/objects |
| 87 | git lfs fetch origin --all |
| 88 | assert_local_object "$oid" 2 |
| 89 | ) |
| 90 | end_test |
| 91 | |
| 92 | begin_test "fetch with bad ref" |
| 93 | ( |
| 94 | set -e |
| 95 | |
| 96 | reponame="fetch-other-branch-required" |
| 97 | setup_remote_repo "$reponame" |
| 98 | clone_repo "$reponame" "$reponame" |
| 99 | |
| 100 | git lfs track "*.dat" |
| 101 | echo "a" > a.dat |
| 102 | git add .gitattributes a.dat |
| 103 | git commit -m "add a.dat" |
| 104 | |
| 105 | git push origin main:other |
| 106 | |
| 107 | # $ echo "a" | shasum -a 256 |
| 108 | oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7" |
| 109 | assert_local_object "$oid" 2 |
| 110 | assert_server_object "$reponame" "$oid" "refs/heads/other" |
| 111 | |
| 112 | rm -rf .git/lfs/objects |
| 113 | GIT_CURL_VERBOSE=1 git lfs fetch --all 2>&1 | tee fetch.log |
| 114 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 115 | echo >&2 "fatal: expected 'git lfs fetch' to fail" |
| 116 | exit 1 |
| 117 | fi |
| 118 | |
| 119 | grep 'Expected ref "refs/heads/other", got "refs/heads/main"' fetch.log |
| 120 | ) |
| 121 | end_test |