| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh" |
| 4 | |
| 5 | # This is a sample Git LFS test. See test/README.md and testhelpers.sh for |
| 6 | # more documentation. |
| 7 | begin_test "happy path" |
| 8 | ( |
| 9 | set -e |
| 10 | |
| 11 | # This initializes a new bare git repository in test/remote. |
| 12 | # These remote repositories are global to every test, so keep the names |
| 13 | # unique. |
| 14 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")" |
| 15 | setup_remote_repo "$reponame" |
| 16 | |
| 17 | # Clone the repository from the test Git server. This is empty, and will be |
| 18 | # used to test a "git pull" below. The repo is cloned to $TRASHDIR/clone |
| 19 | clone_repo "$reponame" clone |
| 20 | |
| 21 | # Clone the repository again to $TRASHDIR/repo. This will be used to commit |
| 22 | # and push objects. |
| 23 | clone_repo "$reponame" repo |
| 24 | |
| 25 | # This executes Git LFS from the local repo that was just cloned. |
| 26 | gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log |
| 27 | grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log |
| 28 | |
| 29 | contents="a" |
| 30 | contents_oid=$(calc_oid "$contents") |
| 31 | |
| 32 | # Regular Git commands can be used. |
| 33 | printfscip-shell system . . printf. "%s" "$contents" > a.dat |
| 34 | gitscip-shell system . . git. add a.dat |
| 35 | gitscip-shell system . . git. add .gitattributes |
| 36 | gitscip-shell system . . git. commit -m "add a.dat" 2>&1 | teescip-shell system . . tee. commit.log |
| 37 | grepscip-shell system . . grep. "main (root-commit)" commit.log |
| 38 | grepscip-shell system . . grep. "2 files changed" commit.log |
| 39 | grepscip-shell system . . grep. "create mode 100644 a.dat" commit.log |
| 40 | grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log |
| 41 | |
| 42 | [scip-shell system . . `[`. "a" = "$(catscip-shell system . . cat. a.dat)" ] |
| 43 | |
| 44 | # This is a small shell function that runs several git commands together. |
| 45 | assert_pointer "main" "a.dat" "$contents_oid" 1 |
| 46 | |
| 47 | refute_server_object "$reponame" "$contents_oid" |
| 48 | |
| 49 | # This pushes to the remote repository set up at the top of the test. |
| 50 | gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log |
| 51 | grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 52 | grepscip-shell system . . grep. "main -> main" push.log |
| 53 | |
| 54 | assert_server_object "$reponame" "$contents_oid" |
| 55 | |
| 56 | # change to the clone's working directory |
| 57 | cd ../clone |
| 58 | |
| 59 | gitscip-shell system . . git. pull origin main |
| 60 | |
| 61 | [scip-shell system . . `[`. "a" = "$(catscip-shell system . . cat. a.dat)" ] |
| 62 | |
| 63 | assert_pointer "main" "a.dat" "$contents_oid" 1 |
| 64 | ) |
| 65 | end_test |
| 66 | |
| 67 | begin_test "happy path on non-origin remote" |
| 68 | ( |
| 69 | set -e |
| 70 | |
| 71 | reponame="happy-without-origin" |
| 72 | setup_remote_repo "$reponame" |
| 73 | |
| 74 | clone_repo "$reponame" repo-without-origin |
| 75 | gitscip-shell system . . git. lfs track "*.dat" |
| 76 | gitscip-shell system . . git. add .gitattributes |
| 77 | gitscip-shell system . . git. commit -m "track" |
| 78 | gitscip-shell system . . git. push origin main |
| 79 | |
| 80 | clone_repo "$reponame" clone-without-origin |
| 81 | gitscip-shell system . . git. remote rename origin happy-path |
| 82 | |
| 83 | cd ../repo-without-origin |
| 84 | echoscip-shell system . . echo. "a" > a.dat |
| 85 | gitscip-shell system . . git. add a.dat |
| 86 | gitscip-shell system . . git. commit -m "boom" |
| 87 | gitscip-shell system . . git. push origin main |
| 88 | |
| 89 | cd ../clone-without-origin |
| 90 | echoscip-shell system . . echo. "remotes:" |
| 91 | gitscip-shell system . . git. remote |
| 92 | gitscip-shell system . . git. pull happy-path main |
| 93 | ) |
| 94 | end_test |
| 95 | |
| 96 | begin_test "happy path on good ref" |
| 97 | ( |
| 98 | set -e |
| 99 | |
| 100 | reponame="happy-path-main-branch-required" |
| 101 | setup_remote_repo "$reponame" |
| 102 | clone_repo "$reponame" "$reponame" |
| 103 | |
| 104 | gitscip-shell system . . git. lfs track "*.dat" |
| 105 | echoscip-shell system . . echo. "a" > a.dat |
| 106 | gitscip-shell system . . git. add .gitattributes a.dat |
| 107 | gitscip-shell system . . git. commit -m "add a.dat" |
| 108 | |
| 109 | gitscip-shell system . . git. push origin main |
| 110 | |
| 111 | # $ echo "a" | shasum -a 256 |
| 112 | oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7" |
| 113 | assert_local_object "$oid" 2 |
| 114 | assert_server_object "$reponame" "$oid" "refs/heads/main" |
| 115 | |
| 116 | clone_repo "$reponame" "$reponame-clone" |
| 117 | assert_local_object "$oid" 2 |
| 118 | ) |
| 119 | end_test |
| 120 | |
| 121 | begin_test "happy path on tracked ref" |
| 122 | ( |
| 123 | set -e |
| 124 | |
| 125 | reponame="happy-path-tracked-branch-required" |
| 126 | setup_remote_repo "$reponame" |
| 127 | clone_repo "$reponame" "$reponame" |
| 128 | |
| 129 | gitscip-shell system . . git. lfs track "*.dat" |
| 130 | echoscip-shell system . . echo. "a" > a.dat |
| 131 | gitscip-shell system . . git. add .gitattributes a.dat |
| 132 | gitscip-shell system . . git. commit -m "add a.dat" |
| 133 | |
| 134 | gitscip-shell system . . git. push origin main:tracked |
| 135 | |
| 136 | # $ echo "a" | shasum -a 256 |
| 137 | oid="87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7" |
| 138 | assert_local_object "$oid" 2 |
| 139 | assert_server_object "$reponame" "$oid" "refs/heads/tracked" |
| 140 | |
| 141 | gitscip-shell system . . git. lfs clone "$GITSERVER/$reponame" --exclude "*" |
| 142 | |
| 143 | gitscip-shell system . . git. config credential.helper lfstest |
| 144 | gitscip-shell system . . git. config push.default upstream |
| 145 | gitscip-shell system . . git. config branch.main.merge refs/heads/tracked |
| 146 | |
| 147 | gitscip-shell system . . git. checkout |
| 148 | assert_local_object "$oid" 2 |
| 149 | ) |
| 150 | end_test |
| 151 | |
| 152 | begin_test "clears local temp objects" |
| 153 | ( |
| 154 | set -e |
| 155 | |
| 156 | mkdirscip-shell system . . mkdir. repo-temp-objects |
| 157 | cd repo-temp-objects |
| 158 | gitscip-shell system . . git. init |
| 159 | |
| 160 | # abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01 |
| 161 | mkdirscip-shell system . . mkdir. -p .git/lfs/objects/go/od |
| 162 | mkdirscip-shell system . . mkdir. -p .git/lfs/tmp/objects |
| 163 | |
| 164 | touchscip-shell system . . touch. .git/lfs/objects/go/od/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx |
| 165 | touchscip-shell system . . touch. .git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand123 |
| 166 | touchscip-shell system . . touch. .git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand456 |
| 167 | touchscip-shell system . . touch. .git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand123 |
| 168 | touchscip-shell system . . touch. .git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand456 |
| 169 | |
| 170 | GIT_TRACE=5 gitscip-shell system . . git. lfs env |
| 171 | |
| 172 | # object file exists |
| 173 | [scip-shell system . . `[`. -e ".git/lfs/objects/go/od/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx" ] |
| 174 | |
| 175 | # newer tmp files exist |
| 176 | [scip-shell system . . `[`. -e ".git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand123" ] |
| 177 | [scip-shell system . . `[`. -e ".git/lfs/tmp/objects/badabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxy-rand456" ] |
| 178 | |
| 179 | # existing tmp files were cleaned up |
| 180 | [scip-shell system . . `[`. ! -e ".git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand123" ] |
| 181 | [scip-shell system . . `[`. ! -e ".git/lfs/tmp/objects/goodabcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwx-rand456" ] |
| 182 | ) |
| 183 | end_test |