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

     1  #!/usr/bin/env bash
     2  
     3  . "$(dirname "$0")/testlib.sh"
     4  
     5  begin_test "verify with retries"
     6  (
     7    set -e
     8  
     9    reponame="verify-fail-2-times"
    10    setup_remote_repo "$reponame"
    11    clone_repo "$reponame" "$reponame"
    12  
    13    git lfs track "*.dat"
    14    git add .gitattributes
    15    git commit -m "initial commit"
    16  
    17    contents="send-verify-action"
    18    contents_oid="$(calc_oid "$contents")"
    19    contents_short_oid="$(echo "$contents_oid" | head -c 7)"
    20    printf "$contents" > a.dat
    21  
    22    git add a.dat
    23    git commit -m "add a.dat"
    24  
    25    GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin master 2>&1 | tee push.log
    26  
    27    grep "Authorization: Basic * * * * *" push.log
    28  
    29    [ "0" -eq "${PIPESTATUS[0]}" ]
    30    [ "2" -eq "$(grep -c "verify $contents_short_oid attempt" push.log)" ]
    31  )
    32  end_test
    33  
    34  begin_test "verify with retries (success without retry)"
    35  (
    36    set -e
    37  
    38    reponame="verify-fail-0-times"
    39    setup_remote_repo "$reponame"
    40    clone_repo "$reponame" "$reponame"
    41  
    42    git lfs track "*.dat"
    43    git add .gitattributes
    44    git commit -m "initial commit"
    45  
    46    contents="send-verify-action"
    47    contents_oid="$(calc_oid "$contents")"
    48    contents_short_oid="$(echo "$contents_oid" | head -c 7)"
    49    printf "$contents" > a.dat
    50  
    51    git add a.dat
    52    git commit -m "add a.dat"
    53  
    54    GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin master 2>&1 | tee push.log
    55  
    56    grep "Authorization: Basic * * * * *" push.log
    57  
    58    [ "0" -eq "${PIPESTATUS[0]}" ]
    59    [ "1" -eq "$(grep -c "verify $contents_short_oid attempt" push.log)" ]
    60  )
    61  end_test
    62  
    63  begin_test "verify with retries (insufficient retries)"
    64  (
    65    set -e
    66  
    67    reponame="verify-fail-10-times"
    68    setup_remote_repo "$reponame"
    69    clone_repo "$reponame" "$reponame"
    70  
    71    git lfs track "*.dat"
    72    git add .gitattributes
    73    git commit -m "initial commit"
    74  
    75    contents="send-verify-action"
    76    contents_oid="$(calc_oid "$contents")"
    77    contents_short_oid="$(echo "$contents_oid" | head -c 7)"
    78    printf "$contents" > a.dat
    79  
    80    git add a.dat
    81    git commit -m "add a.dat"
    82  
    83    set +e
    84    GIT_TRACE=1 git push origin master 2>&1 | tee push.log
    85    if [ "0" -eq "${PIPESTATUS[0]}" ]; then
    86      echo >&2 "verify: expected \"git push\" to fail, didn't ..."
    87      exit 1
    88    fi
    89    set -e
    90  
    91    [ "3" -eq "$(grep -c "verify $contents_short_oid attempt" push.log)" ]
    92  )
    93  end_test
    94  
    95  begin_test "verify with retries (bad .gitconfig)"
    96  (
    97    set -e
    98  
    99    reponame="bad-config-verify-fail-2-times"
   100    setup_remote_repo "$reponame"
   101    clone_repo "$reponame" "$reponame"
   102  
   103    # Invalid `lfs.transfer.maxverifies` will default to 3.
   104    git config "lfs.transfer.maxverifies" "-1"
   105  
   106    git lfs track "*.dat"
   107    git add .gitattributes
   108    git commit -m "initial commit"
   109  
   110    contents="send-verify-action"
   111    contents_oid="$(calc_oid "$contents")"
   112    contents_short_oid="$(echo "$contents_oid" | head -c 7)"
   113    printf "$contents" > a.dat
   114  
   115    git add a.dat
   116    git commit -m "add a.dat"
   117  
   118    GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin master 2>&1 | tee push.log
   119  
   120    grep "Authorization: Basic * * * * *" push.log
   121  
   122    [ "0" -eq "${PIPESTATUS[0]}" ]
   123    [ "2" -eq "$(grep -c "verify $contents_short_oid attempt" push.log)" ]
   124  )
   125  end_test