| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "smudge" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" repo |
| 12 | |
| 13 | gitscip-shell system . . git. lfs track "*.dat" |
| 14 | echoscip-shell system . . echo. "smudge a" > a.dat |
| 15 | gitscip-shell system . . git. add .gitattributes a.dat |
| 16 | gitscip-shell system . . git. commit -m "add a.dat" |
| 17 | |
| 18 | # smudge works even though it hasn't been pushed, by reading from .git/lfs/objects |
| 19 | output="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | gitscip-shell system . . git. lfs smudge)" |
| 20 | [scip-shell system . . `[`. "smudge a" = "$output" ] |
| 21 | |
| 22 | gitscip-shell system . . git. push origin main |
| 23 | |
| 24 | # download it from the git lfs server |
| 25 | rmscip-shell system . . rm. -rf .git/lfs/objects |
| 26 | output="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | gitscip-shell system . . git. lfs smudge)" |
| 27 | [scip-shell system . . `[`. "smudge a" = "$output" ] |
| 28 | ) |
| 29 | end_test |
| 30 | |
| 31 | begin_test "smudge with temp file" |
| 32 | ( |
| 33 | set -e |
| 34 | |
| 35 | cd repo |
| 36 | |
| 37 | rmscip-shell system . . rm. -rf .git/lfs/objects |
| 38 | mkdirscip-shell system . . mkdir. -p .git/lfs/tmp/objects |
| 39 | touchscip-shell system . . touch. .git/lfs/tmp/objects/fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254-1 |
| 40 | pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | GIT_TRACE=5 gitscip-shell system . . git. lfs smudge | teescip-shell system . . tee. smudge.log |
| 41 | [scip-shell system . . `[`. "smudge a" = "$(catscip-shell system . . cat. smudge.log)" ] || { |
| 42 | rmscip-shell system . . rm. -rf .git/lfs/tmp |
| 43 | gitscip-shell system . . git. lfs logs last |
| 44 | exit 1 |
| 45 | } |
| 46 | ) |
| 47 | end_test |
| 48 | |
| 49 | begin_test "smudge with invalid pointer" |
| 50 | ( |
| 51 | set -e |
| 52 | |
| 53 | cd repo |
| 54 | [scip-shell system . . `[`. "wat" = "$(echoscip-shell system . . echo. "wat" | gitscip-shell system . . git. lfs smudge)" ] |
| 55 | [scip-shell system . . `[`. "not a git-lfs file" = "$(echoscip-shell system . . echo. "not a git-lfs file" | gitscip-shell system . . git. lfs smudge)" ] |
| 56 | [scip-shell system . . `[`. "version " = "$(echoscip-shell system . . echo. "version " | gitscip-shell system . . git. lfs smudge)" ] |
| 57 | |
| 58 | # Test with input data larger than the internal memory buffer used |
| 59 | # to spool data between streams, so a temporary file is used as well. |
| 60 | # See https://github.com/git-lfs/git-lfs/pull/1922, |
| 61 | # https://github.com/git-lfs/git-lfs/pull/1932, |
| 62 | # and https://github.com/git-lfs/git-lfs/pull/5617. |
| 63 | max_spool_mem_buffer_size="$(lfstest-getlimit --max-spool-mem-buffer-size)" |
| 64 | spool="$(lfstest-genrandom --base64 $((max_spool_mem_buffer_size * 2)))" |
| 65 | [scip-shell system . . `[`. "$spool" = "$(printfscip-shell system . . printf. "%s" "$spool" | gitscip-shell system . . git. lfs smudge)" ] |
| 66 | ) |
| 67 | end_test |
| 68 | |
| 69 | begin_test "smudge with pointer extension" |
| 70 | ( |
| 71 | set -e |
| 72 | |
| 73 | reponame="smudge-pointer-extension" |
| 74 | gitscip-shell system . . git. init "$reponame" |
| 75 | cd "$reponame" |
| 76 | |
| 77 | setup_case_inverter_extension |
| 78 | |
| 79 | gitscip-shell system . . git. lfs track "*.dat" |
| 80 | |
| 81 | contents="$(printfscip-shell system . . printf. "%s\n%s" "abc" "def")" |
| 82 | contents_oid="$(calc_oid "$contents")" |
| 83 | inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")" |
| 84 | mkdirscip-shell system . . mkdir. dir1 |
| 85 | printfscip-shell system . . printf. "%s" "$contents" >dir1/abc.dat |
| 86 | gitscip-shell system . . git. add .gitattributes dir1 |
| 87 | |
| 88 | pointer="$(case_inverter_extension_pointer "$contents_oid" "$inverted_contents_oid" 7)" |
| 89 | |
| 90 | assert_local_object "$inverted_contents_oid" 7 |
| 91 | |
| 92 | # smudge works even though it hasn't been pushed, by reading from .git/lfs/objects |
| 93 | [scip-shell system . . `[`. "$contents" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge -- "dir1/abc.dat")" ] |
| 94 | grepscip-shell system . . grep. "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 95 | ) |
| 96 | end_test |
| 97 | |
| 98 | begin_test "smudge include/exclude" |
| 99 | ( |
| 100 | set -e |
| 101 | |
| 102 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-includeexclude" |
| 103 | setup_remote_repo "$reponame" |
| 104 | clone_repo "$reponame" includeexclude |
| 105 | |
| 106 | gitscip-shell system . . git. lfs track "*.dat" |
| 107 | echoscip-shell system . . echo. "smudge a" > a.dat |
| 108 | gitscip-shell system . . git. add .gitattributes a.dat |
| 109 | gitscip-shell system . . git. commit -m "add a.dat" |
| 110 | |
| 111 | pointer="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9)" |
| 112 | |
| 113 | # smudge works even though it hasn't been pushed, by reading from .git/lfs/objects |
| 114 | [scip-shell system . . `[`. "smudge a" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge)" ] |
| 115 | |
| 116 | gitscip-shell system . . git. push origin main |
| 117 | |
| 118 | # this WOULD download except we're going to prevent it with include/exclude |
| 119 | rmscip-shell system . . rm. -rf .git/lfs/objects |
| 120 | gitscip-shell system . . git. config "lfs.fetchexclude" "a*" |
| 121 | |
| 122 | [scip-shell system . . `[`. "$pointer" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge a.dat)" ] |
| 123 | |
| 124 | mkdirscip-shell system . . mkdir. -p foo/bar |
| 125 | echoscip-shell system . . echo. "smudge a" > foo/a.dat |
| 126 | echoscip-shell system . . echo. "smudge a" > foo/bar/a.dat |
| 127 | gitscip-shell system . . git. add foo |
| 128 | gitscip-shell system . . git. commit -m 'add foo' |
| 129 | |
| 130 | gitscip-shell system . . git. push origin main |
| 131 | |
| 132 | # The Git LFS objects for a.dat and foo/bar/a.dat would both download except |
| 133 | # we're going to prevent them from doing so with include/exclude. |
| 134 | rmscip-shell system . . rm. -rf .git/lfs/objects |
| 135 | # We also need to prevent MSYS from rewriting /foo into a Windows path. |
| 136 | MSYS_NO_PATHCONV=1 gitscip-shell system . . git. config "lfs.fetchinclude" "/fooscip-shell filesystem . . `/foo`." |
| 137 | MSYS_NO_PATHCONV=1 gitscip-shell system . . git. config "lfs.fetchexclude" "/foo/barscip-shell filesystem . . `/foo/bar`." |
| 138 | |
| 139 | [scip-shell system . . `[`. "$pointer" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge a.dat)" ] |
| 140 | [scip-shell system . . `[`. "smudge a" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge foo/a.dat)" ] |
| 141 | [scip-shell system . . `[`. "$pointer" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge foo/bar/a.dat)" ] |
| 142 | ) |
| 143 | end_test |
| 144 | |
| 145 | begin_test "smudge with skip" |
| 146 | ( |
| 147 | set -e |
| 148 | |
| 149 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-skip" |
| 150 | setup_remote_repo "$reponame" |
| 151 | clone_repo "$reponame" "skip" |
| 152 | |
| 153 | gitscip-shell system . . git. lfs track "*.dat" |
| 154 | echoscip-shell system . . echo. "smudge a" > a.dat |
| 155 | gitscip-shell system . . git. add .gitattributes a.dat |
| 156 | gitscip-shell system . . git. commit -m "add a.dat" |
| 157 | |
| 158 | pointer="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9)" |
| 159 | [scip-shell system . . `[`. "smudge a" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge)" ] |
| 160 | |
| 161 | gitscip-shell system . . git. push origin main |
| 162 | |
| 163 | # Must clear the cache because smudge will use |
| 164 | # cached objects even with --skip/GIT_LFS_SKIP_SMUDGE |
| 165 | # (--skip applies to whether or not it downloads). |
| 166 | rmscip-shell system . . rm. -rf .git/lfs/objects |
| 167 | |
| 168 | [scip-shell system . . `[`. "$pointer" = "$(echoscip-shell system . . echo. "$pointer" | GIT_LFS_SKIP_SMUDGE=1 gitscip-shell system . . git. lfs smudge)" ] |
| 169 | |
| 170 | echoscip-shell system . . echo. "test clone with env" |
| 171 | export GIT_LFS_SKIP_SMUDGE=1 |
| 172 | envscip-shell system . . env. | grepscip-shell system . . grep. LFS_SKIP |
| 173 | clone_repo "$reponame" "skip-clone-env" |
| 174 | [scip-shell system . . `[`. "$pointer" = "$(catscip-shell system . . cat. a.dat)" ] |
| 175 | |
| 176 | gitscip-shell system . . git. lfs pull |
| 177 | [scip-shell system . . `[`. "smudge a" = "$(catscip-shell system . . cat. a.dat)" ] |
| 178 | |
| 179 | echoscip-shell system . . echo. "test clone without env" |
| 180 | unset GIT_LFS_SKIP_SMUDGE |
| 181 | clone_repo "$reponame" "no-skip" |
| 182 | [scip-shell system . . `[`. "smudge a" = "$(catscip-shell system . . cat. a.dat)" ] |
| 183 | |
| 184 | echoscip-shell system . . echo. "test clone with init --skip-smudge" |
| 185 | gitscip-shell system . . git. lfs install --skip-smudge |
| 186 | clone_repo "$reponame" "skip-clone-init" |
| 187 | [scip-shell system . . `[`. "$pointer" = "$(catscip-shell system . . cat. a.dat)" ] |
| 188 | |
| 189 | gitscip-shell system . . git. lfs install --force |
| 190 | ) |
| 191 | end_test |
| 192 | |
| 193 | begin_test "smudge clone with include/exclude" |
| 194 | ( |
| 195 | set -e |
| 196 | |
| 197 | reponame="smudge_include_exclude" |
| 198 | setup_remote_repo "$reponame" |
| 199 | |
| 200 | clone_repo "$reponame" "repo_$reponame" |
| 201 | |
| 202 | gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log |
| 203 | grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log |
| 204 | |
| 205 | contents="a" |
| 206 | contents_oid=$(calc_oid "$contents") |
| 207 | |
| 208 | printfscip-shell system . . printf. "%s" "$contents" > a.dat |
| 209 | gitscip-shell system . . git. add a.dat |
| 210 | gitscip-shell system . . git. add .gitattributes |
| 211 | gitscip-shell system . . git. commit -m "add a.dat" 2>&1 | teescip-shell system . . tee. commit.log |
| 212 | grepscip-shell system . . grep. "main (root-commit)" commit.log |
| 213 | grepscip-shell system . . grep. "2 files changed" commit.log |
| 214 | grepscip-shell system . . grep. "create mode 100644 a.dat" commit.log |
| 215 | grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log |
| 216 | |
| 217 | [scip-shell system . . `[`. "a" = "$(catscip-shell system . . cat. a.dat)" ] |
| 218 | |
| 219 | assert_local_object "$contents_oid" 1 |
| 220 | |
| 221 | gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log |
| 222 | grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log |
| 223 | grepscip-shell system . . grep. "main -> main" push.log |
| 224 | |
| 225 | assert_server_object "$reponame" "$contents_oid" |
| 226 | |
| 227 | clone="$TRASHDIR/clone_$reponame" |
| 228 | gitscip-shell system . . git. -c lfs.fetchexclude="a*" clone "$GITSERVER/$reponame" "$clone" |
| 229 | pushd "$clone" |
| 230 | # Should have succeeded but not downloaded |
| 231 | refute_local_object "$contents_oid" |
| 232 | popd |
| 233 | rmscip-shell system . . rm. -rf "$clone" |
| 234 | |
| 235 | contents2="b" |
| 236 | contents2_oid=$(calc_oid "$contents2") |
| 237 | contents3="c" |
| 238 | contents3_oid=$(calc_oid "$contents3") |
| 239 | |
| 240 | mkdirscip-shell system . . mkdir. -p foo/bar |
| 241 | printfscip-shell system . . printf. "%s" "$contents2" > foo/b.dat |
| 242 | printfscip-shell system . . printf. "%s" "$contents3" > foo/bar/c.dat |
| 243 | gitscip-shell system . . git. add foo |
| 244 | gitscip-shell system . . git. commit -m 'add foo' |
| 245 | |
| 246 | assert_local_object "$contents2_oid" 1 |
| 247 | assert_local_object "$contents3_oid" 1 |
| 248 | |
| 249 | gitscip-shell system . . git. push origin main |
| 250 | |
| 251 | assert_server_object "$reponame" "$contents2_oid" |
| 252 | assert_server_object "$reponame" "$contents3_oid" |
| 253 | |
| 254 | # The Git LFS objects for a.dat and foo/bar/a.dat would both download except |
| 255 | # we're going to prevent them from doing so with include/exclude. |
| 256 | # We also need to prevent MSYS from rewriting /foo into a Windows path. |
| 257 | MSYS_NO_PATHCONV=1 gitscip-shell system . . git. config --global "lfs.fetchinclude" "/fooscip-shell filesystem . . `/foo`." |
| 258 | MSYS_NO_PATHCONV=1 gitscip-shell system . . git. config --global "lfs.fetchexclude" "/foo/barscip-shell filesystem . . `/foo/bar`." |
| 259 | gitscip-shell system . . git. clone "$GITSERVER/$reponame" "$clone" |
| 260 | pushd "$clone" |
| 261 | refute_local_object "$contents_oid" |
| 262 | assert_local_object "$contents2_oid" 1 |
| 263 | refute_local_object "$contents3_oid" |
| 264 | popd |
| 265 | ) |
| 266 | end_test |
| 267 | |
| 268 | begin_test "smudge skip download failure" |
| 269 | ( |
| 270 | set -e |
| 271 | |
| 272 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-skipdownloadfail" |
| 273 | setup_remote_repo "$reponame" |
| 274 | clone_repo "$reponame" skipdownloadfail |
| 275 | |
| 276 | gitscip-shell system . . git. lfs track "*.dat" |
| 277 | echoscip-shell system . . echo. "smudge a" > a.dat |
| 278 | gitscip-shell system . . git. add .gitattributes a.dat |
| 279 | gitscip-shell system . . git. commit -m "add a.dat" |
| 280 | |
| 281 | pointer="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9)" |
| 282 | |
| 283 | # smudge works even though it hasn't been pushed, by reading from .git/lfs/objects |
| 284 | [scip-shell system . . `[`. "smudge a" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge)" ] |
| 285 | |
| 286 | gitscip-shell system . . git. push origin main |
| 287 | |
| 288 | # make it try to download but we're going to make it fail |
| 289 | rmscip-shell system . . rm. -rf .git/lfs/objects |
| 290 | gitscip-shell system . . git. remote set-url origin httpnope://nope.com/nope |
| 291 | |
| 292 | # this should fail |
| 293 | set +e |
| 294 | echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge a.dat; testscip-shell system . . test. ${PIPESTATUS[1]} -ne 0 |
| 295 | set -e |
| 296 | |
| 297 | gitscip-shell system . . git. config lfs.skipdownloaderrors true |
| 298 | echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge a.dat |
| 299 | |
| 300 | # check content too |
| 301 | [scip-shell system . . `[`. "$pointer" = "$(echoscip-shell system . . echo. "$pointer" | gitscip-shell system . . git. lfs smudge a.dat)" ] |
| 302 | |
| 303 | # now try env var |
| 304 | gitscip-shell system . . git. config --unset lfs.skipdownloaderrors |
| 305 | |
| 306 | echoscip-shell system . . echo. "$pointer" | GIT_LFS_SKIP_DOWNLOAD_ERRORS=1 gitscip-shell system . . git. lfs smudge a.dat |
| 307 | |
| 308 | ) |
| 309 | end_test |
| 310 | |
| 311 | begin_test "smudge no ref, non-origin" |
| 312 | ( |
| 313 | set -e |
| 314 | |
| 315 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-no-ref-non-origin" |
| 316 | setup_remote_repo "$reponame" |
| 317 | clone_repo "$reponame" "$reponame-1" |
| 318 | |
| 319 | gitscip-shell system . . git. lfs track "*.dat" |
| 320 | echoscip-shell system . . echo. "smudge a" > a.dat |
| 321 | gitscip-shell system . . git. add .gitattributes a.dat |
| 322 | gitscip-shell system . . git. commit -m "add a.dat" |
| 323 | |
| 324 | gitscip-shell system . . git. push origin main |
| 325 | main=$(gitscip-shell system . . git. rev-parse main) |
| 326 | |
| 327 | cd .. |
| 328 | gitscip-shell system . . git. init "$reponame" |
| 329 | cd "$reponame" |
| 330 | |
| 331 | # We intentionally pick a name that is not origin to exercise the remote |
| 332 | # selection code path. Since there is only one remote, we should use it |
| 333 | # regardless of its name |
| 334 | gitscip-shell system . . git. config remote.random.url "$GITSERVER/$reponame" |
| 335 | gitscip-shell system . . git. fetch "$GITSERVER/$reponame" |
| 336 | |
| 337 | gitscip-shell system . . git. checkout "$main" |
| 338 | [scip-shell system . . `[`. "smudge a" = "$(catscip-shell system . . cat. a.dat)" ] |
| 339 | ) |
| 340 | end_test |