| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh" |
| 4 | |
| 5 | # Only test with Git version 2.11.0 and above as that version introduced |
| 6 | # support for the "filter" attribute and protocol. |
| 7 | ensure_git_version_isnt $VERSION_LOWER "2.11.0" |
| 8 | |
| 9 | begin_test "filter process: checking out a branch" |
| 10 | ( |
| 11 | set -e |
| 12 | |
| 13 | reponame="filter_process_checkout" |
| 14 | setup_remote_repo "$reponame" |
| 15 | clone_repo "$reponame" repo |
| 16 | |
| 17 | gitscip-shell system . . git. lfs track "*.dat" |
| 18 | gitscip-shell system . . git. add .gitattributes |
| 19 | gitscip-shell system . . git. commit -m "initial commit" |
| 20 | |
| 21 | contents_a="contents_a" |
| 22 | contents_a_oid="$(calc_oid $contents_a)" |
| 23 | printfscip-shell system . . printf. "%s" "$contents_a" > a.dat |
| 24 | |
| 25 | gitscip-shell system . . git. add a.dat |
| 26 | gitscip-shell system . . git. commit -m "add a.dat" |
| 27 | |
| 28 | gitscip-shell system . . git. checkout -b b |
| 29 | |
| 30 | contents_b="contents_b" |
| 31 | contents_b_oid="$(calc_oid $contents_b)" |
| 32 | printfscip-shell system . . printf. "%s" "$contents_b" > b.dat |
| 33 | |
| 34 | gitscip-shell system . . git. add b.dat |
| 35 | gitscip-shell system . . git. commit -m "add b.dat" |
| 36 | |
| 37 | gitscip-shell system . . git. push origin --all |
| 38 | |
| 39 | pushd .. |
| 40 | # Git will choose filter.lfs.process over `filter.lfs.clean` and |
| 41 | # `filter.lfs.smudge` |
| 42 | GIT_TRACE_PACKET=1 gitscip-shell system . . git. \ |
| 43 | -c "filter.lfs.process=git-lfs filter-process" \ |
| 44 | -c "filter.lfs.clean=false"\ |
| 45 | -c "filter.lfs.smudge=false" \ |
| 46 | -c "filter.lfs.required=true" \ |
| 47 | clone "$GITSERVER/$reponame" "$reponame-assert" |
| 48 | |
| 49 | cd "$reponame-assert" |
| 50 | |
| 51 | # Assert that we are on the "main" branch, and have a.dat |
| 52 | [scip-shell system . . `[`. "main" = "$(gitscip-shell system . . git. rev-parse --abbrev-ref HEAD)" ] |
| 53 | [scip-shell system . . `[`. "$contents_a" = "$(catscip-shell system . . cat. a.dat)" ] |
| 54 | assert_pointer "main" "a.dat" "$contents_a_oid" 10 |
| 55 | |
| 56 | gitscip-shell system . . git. checkout b |
| 57 | |
| 58 | # Assert that we are on the "b" branch, and have b.dat |
| 59 | [scip-shell system . . `[`. "b" = "$(gitscip-shell system . . git. rev-parse --abbrev-ref HEAD)" ] |
| 60 | [scip-shell system . . `[`. "$contents_b" = "$(catscip-shell system . . cat. b.dat)" ] |
| 61 | assert_pointer "b" "b.dat" "$contents_b_oid" 10 |
| 62 | popd |
| 63 | ) |
| 64 | end_test |
| 65 | |
| 66 | begin_test "filter process: include/exclude" |
| 67 | ( |
| 68 | set -e |
| 69 | |
| 70 | reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-includeexclude" |
| 71 | setup_remote_repo "$reponame" |
| 72 | clone_repo "$reponame" "$reponame" |
| 73 | |
| 74 | gitscip-shell system . . git. lfs track "*.dat" |
| 75 | mkdirscip-shell system . . mkdir. -p foo/bar |
| 76 | |
| 77 | contents_a="contents_a" |
| 78 | contents_a_oid="$(calc_oid $contents_a)" |
| 79 | printfscip-shell system . . printf. "%s" "$contents_a" > a.dat |
| 80 | cpscip-shell system . . cp. a.dat foo |
| 81 | cpscip-shell system . . cp. a.dat foo/bar |
| 82 | |
| 83 | gitscip-shell system . . git. add .gitattributes a.dat foo |
| 84 | gitscip-shell system . . git. commit -m "initial commit" |
| 85 | |
| 86 | gitscip-shell system . . git. push origin main |
| 87 | |
| 88 | # The Git LFS objects for a.dat and foo/bar/a.dat would both download except |
| 89 | # we're going to prevent them from doing so with include/exclude. |
| 90 | # We also need to prevent MSYS from rewriting /foo into a Windows path. |
| 91 | MSYS_NO_PATHCONV=1 gitscip-shell system . . git. config --global "lfs.fetchinclude" "/fooscip-shell filesystem . . `/foo`." |
| 92 | MSYS_NO_PATHCONV=1 gitscip-shell system . . git. config --global "lfs.fetchexclude" "/foo/barscip-shell filesystem . . `/foo/bar`." |
| 93 | |
| 94 | pushd .. |
| 95 | # Git will choose filter.lfs.process over `filter.lfs.clean` and |
| 96 | # `filter.lfs.smudge` |
| 97 | GIT_TRACE_PACKET=1 gitscip-shell system . . git. \ |
| 98 | -c "filter.lfs.process=git-lfs filter-process" \ |
| 99 | -c "filter.lfs.clean=false"\ |
| 100 | -c "filter.lfs.smudge=false" \ |
| 101 | -c "filter.lfs.required=true" \ |
| 102 | clone "$GITSERVER/$reponame" "$reponame-assert" |
| 103 | |
| 104 | cd "$reponame-assert" |
| 105 | |
| 106 | pointer="$(pointer "$contents_a_oid" 10)" |
| 107 | |
| 108 | [scip-shell system . . `[`. "$pointer" = "$(catscip-shell system . . cat. a.dat)" ] |
| 109 | assert_pointer "main" "a.dat" "$contents_a_oid" 10 |
| 110 | |
| 111 | [scip-shell system . . `[`. "$contents_a" = "$(catscip-shell system . . cat. foo/a.dat)" ] |
| 112 | assert_pointer "main" "foo/a.dat" "$contents_a_oid" 10 |
| 113 | |
| 114 | [scip-shell system . . `[`. "$pointer" = "$(catscip-shell system . . cat. foo/bar/a.dat)" ] |
| 115 | assert_pointer "main" "foo/bar/a.dat" "$contents_a_oid" 10 |
| 116 | popd |
| 117 | ) |
| 118 | end_test |
| 119 | |
| 120 | begin_test "filter process: adding a file" |
| 121 | ( |
| 122 | set -e |
| 123 | |
| 124 | reponame="filter_process_add" |
| 125 | setup_remote_repo "$reponame" |
| 126 | clone_repo "$reponame" "$reponame" |
| 127 | |
| 128 | gitscip-shell system . . git. lfs track "*.dat" |
| 129 | gitscip-shell system . . git. add .gitattributes |
| 130 | gitscip-shell system . . git. commit -m "initial commit" |
| 131 | |
| 132 | contents="contents" |
| 133 | contents_oid="$(calc_oid "$contents")" |
| 134 | printfscip-shell system . . printf. "%s" "$contents" > a.dat |
| 135 | |
| 136 | gitscip-shell system . . git. add a.dat |
| 137 | |
| 138 | expected="$(pointer "$contents_oid" "${#contents}")" |
| 139 | got="$(gitscip-shell system . . git. cat-file -p :a.dat)" |
| 140 | |
| 141 | diffscip-shell system . . diff. -u <(echoscip-shell system . . echo. "$expected") <(echoscip-shell system . . echo. "$got") |
| 142 | ) |
| 143 | end_test |
| 144 | |
| 145 | begin_test "filter-process: pointer extension" |
| 146 | ( |
| 147 | set -e |
| 148 | |
| 149 | reponame="filter-process-pointer-extension" |
| 150 | gitscip-shell system . . git. init "$reponame" |
| 151 | cd "$reponame" |
| 152 | |
| 153 | # Git will choose "filter.lfs.process" over "filter.lfs.clean" and |
| 154 | # "filter.lfs.smudge". |
| 155 | gitscip-shell system . . git. config --global --unset filter.lfs.clean |
| 156 | gitscip-shell system . . git. config --global --unset filter.lfs.smudge |
| 157 | |
| 158 | setup_case_inverter_extension |
| 159 | |
| 160 | gitscip-shell system . . git. lfs track "*.dat" |
| 161 | |
| 162 | contents="$(printfscip-shell system . . printf. "%s\n%s" "abc" "def")" |
| 163 | contents_oid="$(calc_oid "$contents")" |
| 164 | inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")" |
| 165 | mkdirscip-shell system . . mkdir. dir1 |
| 166 | printfscip-shell system . . printf. "%s" "$contents" >dir1/abc.dat |
| 167 | gitscip-shell system . . git. add .gitattributes dir1 |
| 168 | gitscip-shell system . . git. commit -m "initial commit" |
| 169 | |
| 170 | pointer="$(case_inverter_extension_pointer "$contents_oid" "$inverted_contents_oid" 7)" |
| 171 | [scip-shell system . . `[`. "$pointer" = "$(gitscip-shell system . . git. cat-file -p ":dir1/abc.dat")" ] |
| 172 | grepscip-shell system . . grep. "clean: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 173 | |
| 174 | assert_local_object "$inverted_contents_oid" 7 |
| 175 | |
| 176 | rmscip-shell system . . rm. -rf dir1 "$LFSTEST_EXT_LOG" |
| 177 | gitscip-shell system . . git. checkout -- . |
| 178 | [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir1/abc.dat")" ] |
| 179 | grepscip-shell system . . grep. "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 180 | |
| 181 | rmscip-shell system . . rm. -rf dir1 "$LFSTEST_EXT_LOG" |
| 182 | mkdirscip-shell system . . mkdir. dir2 |
| 183 | |
| 184 | pushd dir2 |
| 185 | gitscip-shell system . . git. checkout -- .. |
| 186 | popd |
| 187 | |
| 188 | [scip-shell system . . `[`. "$contents" = "$(catscip-shell system . . cat. "dir1/abc.dat")" ] |
| 189 | grepscip-shell system . . grep. "smudge: dir1/abc.dat" "$LFSTEST_EXT_LOG" |
| 190 | ) |
| 191 | end_test |
| 192 | |
| 193 | begin_test "filter process: non-pointer file of maximum pointer size" |
| 194 | ( |
| 195 | set -e |
| 196 | |
| 197 | mkdirscip-shell system . . mkdir. repo-file-max-pointer-size |
| 198 | cd repo-file-max-pointer-size |
| 199 | gitscip-shell system . . git. init |
| 200 | gitscip-shell system . . git. lfs track "*.dat" |
| 201 | |
| 202 | # Test with a file size equal to the size of the read buffer used when |
| 203 | # decoding pointers. See https://github.com/git-lfs/git-lfs/issues/1697 |
| 204 | # and https://github.com/git-lfs/git-lfs/pull/1699. |
| 205 | max_pointer_size="$(lfstest-getlimit --max-pointer-size)" |
| 206 | headscip-shell system . . head. -c "$max_pointer_size" /dev/zeroscip-shell filesystem . . `/dev/zero`. >first.dat |
| 207 | printfscip-shell system . . printf. "any contents" > second.dat |
| 208 | |
| 209 | gitscip-shell system . . git. add . |
| 210 | ) |
| 211 | end_test |
| 212 | |
| 213 | begin_test "filter process: hash-object --stdin --path does not hang" |
| 214 | ( |
| 215 | set -e |
| 216 | |
| 217 | mkdirscip-shell system . . mkdir. repo-hash-object |
| 218 | cd repo-hash-object |
| 219 | gitscip-shell system . . git. init |
| 220 | gitscip-shell system . . git. lfs track "*.dat" |
| 221 | contents="test" |
| 222 | contents_oid="$(calc_oid "$contents")" |
| 223 | expected="$(pointer "$contents_oid" "${#contents}" | gitscip-shell system . . git. hash-object --stdin)" |
| 224 | |
| 225 | # Test with a file size smaller than the size of the read buffer used when |
| 226 | # decoding pointers. See https://github.com/git-lfs/git-lfs/issues/3884 |
| 227 | # and https://github.com/git-lfs/git-lfs/pull/3902. |
| 228 | max_pointer_size="$(lfstest-getlimit --max-pointer-size)" |
| 229 | headscip-shell system . . head. -c $((max_pointer_size * 1000 / 1024)) /dev/zeroscip-shell filesystem . . `/dev/zero`. >first.dat |
| 230 | echoscip-shell system . . echo. "a" >second.dat |
| 231 | |
| 232 | # Works for existing file longer than the input data. |
| 233 | output="$(printfscip-shell system . . printf. "%s" "$contents"| gitscip-shell system . . git. hash-object --path first.dat --stdin)" |
| 234 | [scip-shell system . . `[`. "$expected" = "$output" ] |
| 235 | # Works for existing file shorter than the input data. |
| 236 | output="$(printfscip-shell system . . printf. "%s" "$contents" | gitscip-shell system . . git. hash-object --path second.dat --stdin)" |
| 237 | [scip-shell system . . `[`. "$expected" = "$output" ] |
| 238 | # Works for absent file. |
| 239 | output="$(printfscip-shell system . . printf. "%s" "$contents" | gitscip-shell system . . git. hash-object --path third.dat --stdin)" |
| 240 | [scip-shell system . . `[`. "$expected" = "$output" ] |
| 241 | |
| 242 | # Test with a file size larger than the maximum length of a Git packet line |
| 243 | # (plus some arbitrary additional padding). |
| 244 | max_pktline_len="$(lfstest-getlimit --max-pktline-len)" |
| 245 | contents_size=$((max_pktline_len + max_pointer_size + 1)) |
| 246 | headscip-shell system . . head. -c "$contents_size" /dev/zeroscip-shell filesystem . . `/dev/zero`. >large.dat |
| 247 | contents_oid="$(calc_oid_file large.dat)" |
| 248 | |
| 249 | expected="$(pointer "$contents_oid" "$contents_size" | gitscip-shell system . . git. hash-object --stdin)" |
| 250 | output="$(gitscip-shell system . . git. hash-object --path large.dat --stdin <large.dat)" |
| 251 | [scip-shell system . . `[`. "$expected" = "$output" ] |
| 252 | |
| 253 | gitscip-shell system . . git. add . |
| 254 | ) |
| 255 | end_test |
| 256 | |
| 257 | begin_test "filter process: checking out a branch with --skip-smudge and checkout-index" |
| 258 | ( |
| 259 | set -e |
| 260 | |
| 261 | reponame="filter-process-skip-smudge-checkout-index" |
| 262 | setup_remote_repo "$reponame" |
| 263 | clone_repo "$reponame" "$reponame" |
| 264 | |
| 265 | gitscip-shell system . . git. lfs track "*.dat" |
| 266 | gitscip-shell system . . git. add .gitattributes |
| 267 | gitscip-shell system . . git. commit -m "initial commit" |
| 268 | |
| 269 | contents_a="contents_a" |
| 270 | contents_a_oid="$(calc_oid $contents_a)" |
| 271 | printfscip-shell system . . printf. "%s" "$contents_a" > a.dat |
| 272 | |
| 273 | gitscip-shell system . . git. add a.dat |
| 274 | gitscip-shell system . . git. commit -m "add a.dat" |
| 275 | |
| 276 | gitscip-shell system . . git. checkout -b b |
| 277 | |
| 278 | contents_b="contents_b" |
| 279 | contents_b_oid="$(calc_oid $contents_b)" |
| 280 | printfscip-shell system . . printf. "%s" "$contents_b" > b.dat |
| 281 | |
| 282 | gitscip-shell system . . git. add b.dat |
| 283 | gitscip-shell system . . git. commit -m "add b.dat" |
| 284 | |
| 285 | gitscip-shell system . . git. lfs install --local --skip-smudge |
| 286 | |
| 287 | gitscip-shell system . . git. checkout main |
| 288 | |
| 289 | rmscip-shell system . . rm. a.dat |
| 290 | gitscip-shell system . . git. checkout-index -af |
| 291 | gitscip-shell system . . git. lfs pointer --check --file a.dat |
| 292 | |
| 293 | assert_pointer "main" "a.dat" "$contents_a_oid" 10 |
| 294 | |
| 295 | gitscip-shell system . . git. checkout b |
| 296 | |
| 297 | rmscip-shell system . . rm. *.dat |
| 298 | gitscip-shell system . . git. checkout-index -af |
| 299 | gitscip-shell system . . git. lfs pointer --check --file a.dat |
| 300 | gitscip-shell system . . git. lfs pointer --check --file b.dat |
| 301 | |
| 302 | # Assert that we are on the "b" branch, and have b.dat |
| 303 | assert_pointer "b" "b.dat" "$contents_b_oid" 10 |
| 304 | ) |
| 305 | end_test |
| 306 | |
| 307 | begin_test "filter process: git archive does not invoke SSH" |
| 308 | ( |
| 309 | set -e |
| 310 | |
| 311 | setup_pure_ssh |
| 312 | |
| 313 | reponame="filter-process-archive" |
| 314 | setup_remote_repo "$reponame" |
| 315 | clone_repo "$reponame" "$reponame" |
| 316 | |
| 317 | sshurl=$(ssh_remote "$reponame") |
| 318 | gitscip-shell system . . git. config lfs.url "$sshurl" |
| 319 | |
| 320 | contents="test" |
| 321 | gitscip-shell system . . git. lfs track "*.dat" |
| 322 | printfscip-shell system . . printf. "%s" "$contents" > test.dat |
| 323 | gitscip-shell system . . git. add .gitattributes test.dat |
| 324 | gitscip-shell system . . git. commit -m "initial commit" |
| 325 | |
| 326 | gitscip-shell system . . git. push origin main 2>&1 |
| 327 | cd .. |
| 328 | GIT_TRACE=1 gitscip-shell system . . git. clone "$sshurl" "$reponame-2" 2>&1 | teescip-shell system . . tee. trace.log |
| 329 | grepscip-shell system . . grep. "lfs-ssh-echo.*git-lfs-transfer .*$reponame.git download" trace.log |
| 330 | cd "$reponame-2" |
| 331 | GIT_TRACE=1 GIT_TRACE_PACKET=1 gitscip-shell system . . git. archive -o foo.tar HEAD 2>&1 | teescip-shell system . . tee. archive.log |
| 332 | grepscip-shell system . . grep. 'pure SSH' archive.log && exit 1 |
| 333 | truescip-shell system . . true. |
| 334 | ) |
| 335 | end_test |
| 336 | |
| 337 | begin_test "filter process: ignore file size on disk when cleaning" |
| 338 | ( |
| 339 | set -e |
| 340 | |
| 341 | reponame="filter-process-ignore-file-size" |
| 342 | setup_remote_repo "$reponame" |
| 343 | clone_repo "$reponame" "$reponame" |
| 344 | |
| 345 | gitscip-shell system . . git. lfs track "*.dat" |
| 346 | gitscip-shell system . . git. add .gitattributes |
| 347 | gitscip-shell system . . git. commit -m "initial commit" |
| 348 | |
| 349 | # Test with a file size larger than the size of the read buffer used when |
| 350 | # decoding pointers. See the secondary issue reported in |
| 351 | # https://github.com/git-lfs/git-lfs/issues/4974#issuecomment-2717907543 |
| 352 | # and https://github.com/git-lfs/git-lfs/pull/6011. |
| 353 | max_pointer_size="$(lfstest-getlimit --max-pointer-size)" |
| 354 | contents_size=$((max_pointer_size * 2)) |
| 355 | headscip-shell system . . head. -c "$contents_size" /dev/zeroscip-shell filesystem . . `/dev/zero`. >large.dat |
| 356 | contents_oid="$(calc_oid_file "large.dat")" |
| 357 | |
| 358 | # To replicate the reported issue, the "git-lfs filter-process" command's |
| 359 | # input from Git should be larger than the size of the pointer read buffer, |
| 360 | # but the file on disk should be smaller, so the lfstest-badlocalfile helper |
| 361 | # renames the initial file after Git has started piping its data, and then |
| 362 | # replaces the file with an empty file. |
| 363 | GIT_TRACE_PACKET=1 gitscip-shell system . . git. \ |
| 364 | -c "filter.lfs.process=lfstest-badlocalfile | git-lfs filter-process" \ |
| 365 | -c "filter.lfs.clean=false"\ |
| 366 | -c "filter.lfs.smudge=false" \ |
| 367 | -c "filter.lfs.required=true" \ |
| 368 | add large.dat 2>&1 | teescip-shell system . . tee. filter.log |
| 369 | [scip-shell system . . `[`. 0 -eq "${PIPESTATUS[0]}" ] |
| 370 | |
| 371 | [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "unknown command" filter.log)" ] |
| 372 | |
| 373 | expected="$(pointer "$contents_oid" "$contents_size")" |
| 374 | got="$(gitscip-shell system . . git. cat-file -p :large.dat)" |
| 375 | |
| 376 | diffscip-shell system . . diff. -u <(echoscip-shell system . . echo. "$expected") <(echoscip-shell system . . echo. "$got") |
| 377 | ) |
| 378 | end_test |