github.com/git-lfs/git-lfs@v2.5.2+incompatible/t/t-resume-http-range.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  . "$(dirname "$0")/testlib.sh"
     4  
     5  begin_test "resume-http-range"
     6  (
     7    set -e
     8  
     9    reponame="$(basename "$0" ".sh")"
    10    setup_remote_repo "$reponame"
    11  
    12    clone_repo "$reponame" $reponame
    13  
    14    git lfs track "*.dat" 2>&1 | tee track.log
    15    grep "Tracking \"\*.dat\"" track.log
    16  
    17    # this string announces to server that we want a test that
    18    # interrupts the transfer when started from 0 to cause resume
    19    contents="status-batch-resume-206"
    20    contents_oid=$(calc_oid "$contents")
    21  
    22    printf "$contents" > a.dat
    23    git add a.dat
    24    git add .gitattributes
    25    git commit -m "add a.dat" 2>&1 | tee commit.log
    26    git push origin master
    27  
    28    assert_server_object "$reponame" "$contents_oid"
    29  
    30    # delete local copy then fetch it back
    31    # server will abort the transfer mid way (so will error) when not resuming
    32    # then we can restart it
    33    rm -rf .git/lfs/objects
    34    git lfs fetch 2>&1 | tee fetchinterrupted.log
    35    refute_local_object "$contents_oid"
    36  
    37    # now fetch again, this should try to resume and server should send remainder
    38    # this time (it does not cut short when Range is requested)
    39    GIT_TRACE=1 git lfs fetch 2>&1 | tee fetchresume.log
    40    grep "xfer: server accepted resume" fetchresume.log
    41    assert_local_object "$contents_oid" "${#contents}"
    42  
    43  )
    44  end_test
    45  
    46  begin_test "resume-http-range-fallback"
    47  (
    48    set -e
    49  
    50    reponame="resume-http-range-fallback"
    51    setup_remote_repo "$reponame"
    52  
    53    clone_repo "$reponame" $reponame
    54  
    55    git lfs track "*.dat" 2>&1 | tee track.log
    56    grep "Tracking \"\*.dat\"" track.log
    57  
    58    # this string announces to server that we want it to abort the download part
    59    # way, but reject the Range: header and fall back on re-downloading instead
    60    contents="batch-resume-fail-fallback"
    61    contents_oid=$(calc_oid "$contents")
    62  
    63    printf "$contents" > a.dat
    64    git add a.dat
    65    git add .gitattributes
    66    git commit -m "add a.dat" 2>&1 | tee commit.log
    67    git push origin master
    68  
    69    assert_server_object "$reponame" "$contents_oid"
    70  
    71    # delete local copy then fetch it back
    72    # server will abort the transfer mid way (so will error) when not resuming
    73    # then we can restart it
    74    rm -rf .git/lfs/objects
    75    git lfs fetch 2>&1 | tee fetchinterrupted.log
    76    refute_local_object "$contents_oid"
    77  
    78    # now fetch again, this should try to resume but server should reject the Range
    79    # header, which should cause client to re-download
    80    GIT_TRACE=1 git lfs fetch 2>&1 | tee fetchresumefallback.log
    81    grep "xfer: server rejected resume" fetchresumefallback.log
    82    # re-download should still have worked
    83    assert_local_object "$contents_oid" "${#contents}"
    84  
    85  )
    86  end_test
    87