github.com/psexton/git-lfs@v2.1.1-0.20170517224304-289a18b2bc53+incompatible/test/test-prune.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  . "test/testlib.sh"
     4  
     5  begin_test "prune unreferenced and old"
     6  (
     7    set -e
     8  
     9    reponame="prune_unref_old"
    10    setup_remote_repo "remote_$reponame"
    11  
    12    clone_repo "remote_$reponame" "clone_$reponame"
    13  
    14    git lfs track "*.dat" 2>&1 | tee track.log
    15    grep "Tracking \"\*.dat\"" track.log
    16  
    17    # generate content we'll use
    18    content_unreferenced="To delete: unreferenced"
    19    content_oldandpushed="To delete: pushed and too old"
    20    content_oldandunchanged="Keep: pushed and created a while ago, but still current"
    21    oid_unreferenced=$(calc_oid "$content_unreferenced")
    22    oid_oldandpushed=$(calc_oid "$content_oldandpushed")
    23    oid_oldandunchanged=$(calc_oid "$content_oldandunchanged")
    24    content_retain1="Retained content 1"
    25    content_retain2="Retained content 2"
    26    oid_retain1=$(calc_oid "$content_retain1")
    27    oid_retain2=$(calc_oid "$content_retain2")
    28  
    29  
    30    # Remember for something to be 'too old' it has to appear on the MINUS side
    31    # of the diff outside the prune window, i.e. it's not when it was introduced
    32    # but when it disappeared from relevance. That's why changes to file1.dat on master
    33    # from 7d ago are included even though the commit itself is outside of the window,
    34    # that content of file1.dat was relevant until it was removed with a commit, inside the window
    35    # think of it as windows of relevance that overlap until the content is replaced
    36  
    37    # we also make sure we commit today on master so that the recent commits measured
    38    # from latest commit on master tracks back from there
    39    echo "[
    40    {
    41      \"CommitDate\":\"$(get_date -20d)\",
    42      \"Files\":[
    43        {\"Filename\":\"old.dat\",\"Size\":${#content_oldandpushed}, \"Data\":\"$content_oldandpushed\"},
    44        {\"Filename\":\"stillcurrent.dat\",\"Size\":${#content_oldandunchanged}, \"Data\":\"$content_oldandunchanged\"}]
    45    },
    46    {
    47      \"CommitDate\":\"$(get_date -7d)\",
    48      \"Files\":[
    49        {\"Filename\":\"old.dat\",\"Size\":${#content_retain1}, \"Data\":\"$content_retain1\"}]
    50    },
    51    {
    52      \"CommitDate\":\"$(get_date -4d)\",
    53      \"NewBranch\":\"branch_to_delete\",
    54      \"Files\":[
    55        {\"Filename\":\"unreferenced.dat\",\"Size\":${#content_unreferenced}, \"Data\":\"$content_unreferenced\"}]
    56    },
    57    {
    58      \"ParentBranches\":[\"master\"],
    59      \"Files\":[
    60        {\"Filename\":\"old.dat\",\"Size\":${#content_retain2}, \"Data\":\"$content_retain2\"}]
    61    }
    62    ]" | lfstest-testutils addcommits
    63  
    64    git push origin master
    65    git branch -D branch_to_delete
    66  
    67    git config lfs.fetchrecentrefsdays 5
    68    git config lfs.fetchrecentremoterefs true
    69    git config lfs.fetchrecentcommitsdays 3
    70    git config lfs.pruneoffsetdays 2
    71  
    72    git lfs prune --dry-run --verbose 2>&1 | tee prune.log
    73  
    74    grep "5 local objects, 3 retained" prune.log
    75    grep "2 files would be pruned" prune.log
    76    grep "$oid_oldandpushed" prune.log
    77    grep "$oid_unreferenced" prune.log
    78  
    79    assert_local_object "$oid_oldandpushed" "${#content_oldandpushed}"
    80    assert_local_object "$oid_unreferenced" "${#content_unreferenced}"
    81    git lfs prune
    82    refute_local_object "$oid_oldandpushed" "${#content_oldandpushed}"
    83    refute_local_object "$oid_unreferenced" "${#content_unreferenced}"
    84    assert_local_object "$oid_retain1" "${#content_retain1}"
    85    assert_local_object "$oid_retain2" "${#content_retain2}"
    86  
    87    # now only keep AT refs, no recents
    88    git config lfs.fetchrecentcommitsdays 0
    89    git lfs prune --verbose 2>&1 | tee prune.log
    90    grep "3 local objects, 2 retained" prune.log
    91    grep "Pruning 1 files" prune.log
    92    grep "$oid_retain1" prune.log
    93    refute_local_object "$oid_retain1"
    94    assert_local_object "$oid_retain2" "${#content_retain2}"
    95  
    96  
    97  
    98  )
    99  end_test
   100  
   101  
   102  begin_test "prune keep unpushed"
   103  (
   104    set -e
   105  
   106    # need to set up many commits on each branch with old data so that would
   107    # get deleted if it were not for unpushed status (heads would never be pruned but old changes would)
   108    reponame="prune_keep_unpushed"
   109    setup_remote_repo "remote_$reponame"
   110  
   111    clone_repo "remote_$reponame" "clone_$reponame"
   112  
   113    git lfs track "*.dat" 2>&1 | tee track.log
   114    grep "Tracking \"\*.dat\"" track.log
   115  
   116  
   117    content_keepunpushedhead1="Keep: unpushed HEAD 1"
   118    content_keepunpushedhead2="Keep: unpushed HEAD 2"
   119    content_keepunpushedhead3="Keep: unpushed HEAD 3"
   120    content_keepunpushedbranch1="Keep: unpushed second branch 1"
   121    content_keepunpushedbranch2="Keep: unpushed second branch 2"
   122    content_keepunpushedbranch3="Keep: unpushed second branch 3"
   123    oid_keepunpushedhead1=$(calc_oid "$content_keepunpushedhead1")
   124    oid_keepunpushedhead2=$(calc_oid "$content_keepunpushedhead2")
   125    oid_keepunpushedhead3=$(calc_oid "$content_keepunpushedhead3")
   126    oid_keepunpushedbranch1=$(calc_oid "$content_keepunpushedbranch1")
   127    oid_keepunpushedbranch2=$(calc_oid "$content_keepunpushedbranch2")
   128    oid_keepunpushedbranch3=$(calc_oid "$content_keepunpushedbranch3")
   129    oid_keepunpushedtagged1=$(calc_oid "$content_keepunpushedtagged1")
   130    oid_keepunpushedtagged2=$(calc_oid "$content_keepunpushedtagged1")
   131  
   132    echo "[
   133    {
   134      \"CommitDate\":\"$(get_date -40d)\",
   135      \"Files\":[
   136        {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedhead1}, \"Data\":\"$content_keepunpushedhead1\"}]
   137    },
   138    {
   139      \"CommitDate\":\"$(get_date -31d)\",
   140      \"ParentBranches\":[\"master\"],
   141      \"NewBranch\":\"branch_unpushed\",
   142      \"Files\":[
   143        {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedbranch1}, \"Data\":\"$content_keepunpushedbranch1\"}]
   144    },
   145    {
   146      \"CommitDate\":\"$(get_date -16d)\",
   147      \"Files\":[
   148        {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedbranch2}, \"Data\":\"$content_keepunpushedbranch2\"}]
   149    },
   150    {
   151      \"CommitDate\":\"$(get_date -2d)\",
   152      \"Files\":[
   153        {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedbranch3}, \"Data\":\"$content_keepunpushedbranch3\"}]
   154    },
   155    {
   156      \"CommitDate\":\"$(get_date -21d)\",
   157      \"ParentBranches\":[\"master\"],
   158      \"Files\":[
   159        {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedhead2}, \"Data\":\"$content_keepunpushedhead2\"}]
   160    },
   161    {
   162      \"CommitDate\":\"$(get_date -0d)\",
   163      \"Files\":[
   164        {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedhead3}, \"Data\":\"$content_keepunpushedhead3\"}]
   165    }
   166    ]" | lfstest-testutils addcommits
   167  
   168    git config lfs.fetchrecentrefsdays 5
   169    git config lfs.fetchrecentremoterefs true
   170    git config lfs.fetchrecentcommitsdays 0 # only keep AT refs, no recents
   171    git config lfs.pruneoffsetdays 2
   172  
   173    git lfs prune 2>&1 | tee prune.log
   174    grep "Nothing to prune" prune.log
   175  
   176    # Now push master and show that older versions on master will be removed
   177    git push origin master
   178  
   179    git lfs prune --verbose 2>&1 | tee prune.log
   180    grep "6 local objects, 4 retained" prune.log
   181    grep "Pruning 2 files" prune.log
   182    grep "$oid_keepunpushedhead1" prune.log
   183    grep "$oid_keepunpushedhead2" prune.log
   184    refute_local_object "$oid_keepunpushedhead1"
   185    refute_local_object "$oid_keepunpushedhead2"
   186  
   187  
   188    # MERGE the secondary branch, delete the branch then push master, then make sure
   189    # we delete the intermediate commits but also make sure they're on server
   190    # resolve conflicts by taking other branch
   191    git merge -Xtheirs branch_unpushed
   192    git branch -D branch_unpushed
   193    git lfs prune --dry-run | grep "Nothing to prune"
   194    git push origin master
   195  
   196    git lfs prune --verbose 2>&1 | tee prune.log
   197    grep "4 local objects, 1 retained" prune.log
   198    grep "Pruning 3 files" prune.log
   199    grep "$oid_keepunpushedbranch1" prune.log
   200    grep "$oid_keepunpushedbranch2" prune.log
   201    grep "$oid_keepunpushedhead3" prune.log
   202    refute_local_object "$oid_keepunpushedbranch1"
   203    refute_local_object "$oid_keepunpushedbranch2"
   204    # we used -Xtheirs so old head state is now obsolete, is the last state on branch
   205    refute_local_object "$oid_keepunpushedhead3"
   206    assert_server_object "remote_$reponame" "$oid_keepunpushedbranch1"
   207    assert_server_object "remote_$reponame" "$oid_keepunpushedbranch2"
   208    assert_server_object "remote_$reponame" "$oid_keepunpushedhead3"
   209  
   210  )
   211  end_test
   212  
   213  begin_test "prune keep recent"
   214  (
   215    set -e
   216  
   217    reponame="prune_recent"
   218    setup_remote_repo "remote_$reponame"
   219  
   220    clone_repo "remote_$reponame" "clone_$reponame"
   221  
   222    git lfs track "*.dat" 2>&1 | tee track.log
   223    grep "Tracking \"\*.dat\"" track.log
   224  
   225    content_keephead="Keep: HEAD"
   226    content_keeprecentbranch1tip="Keep: Recent branch 1 tip"
   227    content_keeprecentbranch2tip="Keep: Recent branch 2 tip"
   228    content_keeprecentcommithead="Keep: Recent commit on HEAD"
   229    content_keeprecentcommitbranch1="Keep: Recent commit on recent branch 1"
   230    content_keeprecentcommitbranch2="Keep: Recent commit on recent branch 2"
   231    content_prunecommitoldbranch1="Prune: old commit on old branch"
   232    content_prunecommitoldbranch2="Prune: old branch tip"
   233    content_prunecommitbranch1="Prune: old commit on recent branch 1"
   234    content_prunecommitbranch2="Prune: old commit on recent branch 2"
   235    content_prunecommithead="Prune: old commit on HEAD"
   236    oid_keephead=$(calc_oid "$content_keephead")
   237    oid_keeprecentbranch1tip=$(calc_oid "$content_keeprecentbranch1tip")
   238    oid_keeprecentbranch2tip=$(calc_oid "$content_keeprecentbranch2tip")
   239    oid_keeprecentcommithead=$(calc_oid "$content_keeprecentcommithead")
   240    oid_keeprecentcommitbranch1=$(calc_oid "$content_keeprecentcommitbranch1")
   241    oid_keeprecentcommitbranch2=$(calc_oid "$content_keeprecentcommitbranch2")
   242    oid_prunecommitoldbranch=$(calc_oid "$content_prunecommitoldbranch1")
   243    oid_prunecommitoldbranch2=$(calc_oid "$content_prunecommitoldbranch2")
   244    oid_prunecommitbranch1=$(calc_oid "$content_prunecommitbranch1")
   245    oid_prunecommitbranch2=$(calc_oid "$content_prunecommitbranch2")
   246    oid_prunecommithead=$(calc_oid "$content_prunecommithead")
   247  
   248  
   249    # use a single file so each commit supercedes the last, if different files
   250    # then history becomes harder to track
   251    # Also note that when considering 'recent' when editing a single file, it means
   252    # that the snapshot state overlapped; so the latest commit *before* the day
   253    # that you're looking at, not just the commits on/after.
   254    echo "[
   255    {
   256      \"CommitDate\":\"$(get_date -50d)\",
   257      \"Files\":[
   258        {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommithead}, \"Data\":\"$content_prunecommithead\"}]
   259    },
   260    {
   261      \"CommitDate\":\"$(get_date -30d)\",
   262      \"Files\":[
   263        {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentcommithead}, \"Data\":\"$content_keeprecentcommithead\"}]
   264    },
   265    {
   266      \"CommitDate\":\"$(get_date -8d)\",
   267      \"NewBranch\":\"branch_old\",
   268      \"Files\":[
   269        {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommitoldbranch1}, \"Data\":\"$content_prunecommitoldbranch1\"}]
   270    },
   271    {
   272      \"CommitDate\":\"$(get_date -7d)\",
   273      \"Files\":[
   274        {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommitoldbranch2}, \"Data\":\"$content_prunecommitoldbranch2\"}]
   275    },
   276    {
   277      \"CommitDate\":\"$(get_date -9d)\",
   278      \"ParentBranches\":[\"master\"],
   279      \"NewBranch\":\"branch1\",
   280      \"Files\":[
   281        {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommitbranch1}, \"Data\":\"$content_prunecommitbranch1\"}]
   282    },
   283    {
   284      \"CommitDate\":\"$(get_date -8d)\",
   285      \"Files\":[
   286        {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentcommitbranch1}, \"Data\":\"$content_keeprecentcommitbranch1\"}]
   287    },
   288    {
   289      \"CommitDate\":\"$(get_date -5d)\",
   290      \"Files\":[
   291        {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentbranch1tip}, \"Data\":\"$content_keeprecentbranch1tip\"}]
   292    },
   293    {
   294      \"CommitDate\":\"$(get_date -17d)\",
   295      \"ParentBranches\":[\"master\"],
   296      \"NewBranch\":\"branch2\",
   297      \"Files\":[
   298        {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommitbranch2}, \"Data\":\"$content_prunecommitbranch2\"}]
   299    },
   300    {
   301      \"CommitDate\":\"$(get_date -10d)\",
   302      \"Files\":[
   303        {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentcommitbranch2}, \"Data\":\"$content_keeprecentcommitbranch2\"}]
   304    },
   305    {
   306      \"CommitDate\":\"$(get_date -2d)\",
   307      \"Files\":[
   308        {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentbranch2tip}, \"Data\":\"$content_keeprecentbranch2tip\"}]
   309    },
   310    {
   311      \"CommitDate\":\"$(get_date -1d)\",
   312      \"ParentBranches\":[\"master\"],
   313      \"Files\":[
   314        {\"Filename\":\"file.dat\",\"Size\":${#content_keephead}, \"Data\":\"$content_keephead\"}]
   315    }
   316    ]" | lfstest-testutils addcommits
   317  
   318    # keep refs for 6 days & any prev commit that overlaps 2 days before tip (recent + offset)
   319    git config lfs.fetchrecentrefsdays 5
   320    git config lfs.fetchrecentremoterefs true
   321    git config lfs.fetchrecentcommitsdays 1
   322    git config lfs.pruneoffsetdays 1
   323  
   324    # push everything so that's not a reason to retain
   325    git push origin master:master branch_old:branch_old branch1:branch1 branch2:branch2
   326  
   327  
   328    git lfs prune --verbose 2>&1 | tee prune.log
   329    grep "11 local objects, 6 retained" prune.log
   330    grep "Pruning 5 files" prune.log
   331    grep "$oid_prunecommitoldbranch" prune.log
   332    grep "$oid_prunecommitoldbranch2" prune.log
   333    grep "$oid_prunecommitbranch1" prune.log
   334    grep "$oid_prunecommitbranch2" prune.log
   335    grep "$oid_prunecommithead" prune.log
   336  
   337    refute_local_object "$oid_prunecommitoldbranch"
   338    refute_local_object "$oid_prunecommitoldbranch2"
   339    refute_local_object "$oid_prunecommitbranch1"
   340    refute_local_object "$oid_prunecommitbranch2"
   341    refute_local_object "$oid_prunecommithead"
   342    assert_local_object "$oid_keephead" "${#content_keephead}"
   343    assert_local_object "$oid_keeprecentbranch1tip" "${#content_keeprecentbranch1tip}"
   344    assert_local_object "$oid_keeprecentbranch2tip" "${#content_keeprecentbranch2tip}"
   345    assert_local_object "$oid_keeprecentcommithead" "${#content_keeprecentcommithead}"
   346    assert_local_object "$oid_keeprecentcommitbranch1" "${#content_keeprecentcommitbranch1}"
   347    assert_local_object "$oid_keeprecentcommitbranch2" "${#content_keeprecentcommitbranch2}"
   348  
   349    # now don't include any recent commits in fetch & hence don't retain
   350    # still retain tips of branches
   351    git config lfs.fetchrecentcommitsdays 0
   352    git lfs prune --verbose 2>&1 | tee prune.log
   353    grep "6 local objects, 3 retained" prune.log
   354    grep "Pruning 3 files" prune.log
   355    assert_local_object "$oid_keephead" "${#content_keephead}"
   356    assert_local_object "$oid_keeprecentbranch1tip" "${#content_keeprecentbranch1tip}"
   357    assert_local_object "$oid_keeprecentbranch2tip" "${#content_keeprecentbranch2tip}"
   358    refute_local_object "$oid_keeprecentcommithead"
   359    refute_local_object "$oid_keeprecentcommitbranch1"
   360    refute_local_object "$oid_keeprecentcommitbranch2"
   361  
   362    # now don't include any recent refs at all, only keep HEAD
   363    git config lfs.fetchrecentrefsdays 0
   364    git lfs prune --verbose 2>&1 | tee prune.log
   365    grep "3 local objects, 1 retained" prune.log
   366    grep "Pruning 2 files" prune.log
   367    assert_local_object "$oid_keephead" "${#content_keephead}"
   368    refute_local_object "$oid_keeprecentbranch1tip"
   369    refute_local_object "$oid_keeprecentbranch2tip"
   370  
   371  )
   372  end_test
   373  
   374  begin_test "prune remote tests"
   375  (
   376    set -e
   377  
   378    reponame="prune_no_or_nonorigin_remote"
   379    git init "$reponame"
   380    cd "$reponame"
   381  
   382    git lfs track "*.dat" 2>&1 | tee track.log
   383    grep "Tracking \"\*.dat\"" track.log
   384  
   385    echo "[
   386    {
   387      \"CommitDate\":\"$(get_date -50d)\",
   388      \"Files\":[
   389        {\"Filename\":\"file.dat\",\"Size\":30}]
   390    },
   391    {
   392      \"CommitDate\":\"$(get_date -40d)\",
   393      \"Files\":[
   394        {\"Filename\":\"file.dat\",\"Size\":28}]
   395    },
   396    {
   397      \"CommitDate\":\"$(get_date -35d)\",
   398      \"Files\":[
   399        {\"Filename\":\"file.dat\",\"Size\":37}]
   400    },
   401    {
   402      \"CommitDate\":\"$(get_date -25d)\",
   403      \"Files\":[
   404        {\"Filename\":\"file.dat\",\"Size\":42}]
   405    }
   406    ]" | lfstest-testutils addcommits
   407  
   408    # set no recents so max ability to prune normally
   409    git config lfs.fetchrecentrefsdays 0
   410    git config lfs.fetchrecentremoterefs true
   411    git config lfs.fetchrecentcommitsdays 0
   412    git config lfs.pruneoffsetdays 1
   413  
   414    # can never prune with no remote
   415    git lfs prune --verbose 2>&1 | tee prune.log
   416    grep "4 local objects, 4 retained" prune.log
   417    grep "Nothing to prune" prune.log
   418  
   419  
   420    # also make sure nothing is pruned when remote is not origin
   421    # create 2 remotes, neither of which is called origin & push to both
   422    setup_remote_repo "remote1_$reponame"
   423    setup_remote_repo "remote2_$reponame"
   424    cd "$TRASHDIR/$reponame"
   425    git remote add not_origin "$GITSERVER/remote1_$reponame"
   426    git push not_origin master
   427  
   428    git lfs prune --verbose 2>&1 | tee prune.log
   429    grep "4 local objects, 4 retained" prune.log
   430    grep "Nothing to prune" prune.log
   431  
   432    # now set the prune remote to be not_origin, should now prune
   433    # do a dry run so we can also verify
   434    git config lfs.pruneremotetocheck not_origin
   435  
   436    git lfs prune --verbose --dry-run 2>&1 | tee prune.log
   437    grep "4 local objects, 1 retained" prune.log
   438    grep "3 files would be pruned" prune.log
   439  
   440  
   441  
   442  )
   443  end_test
   444  
   445  begin_test "prune verify"
   446  (
   447    set -e
   448  
   449    reponame="prune_verify"
   450    setup_remote_repo "remote_$reponame"
   451  
   452    clone_repo "remote_$reponame" "clone_$reponame"
   453  
   454    git lfs track "*.dat" 2>&1 | tee track.log
   455    grep "Tracking \"\*.dat\"" track.log
   456  
   457    content_head="HEAD content"
   458    content_commit3="Content for commit 3 (prune)"
   459    content_commit2_failverify="Content for commit 2 (prune - fail verify)"
   460    content_commit1="Content for commit 1 (prune)"
   461    oid_head=$(calc_oid "$content_head")
   462    oid_commit3=$(calc_oid "$content_commit3")
   463    oid_commit2_failverify=$(calc_oid "$content_commit2_failverify")
   464    oid_commit1=$(calc_oid "$content_commit1")
   465  
   466    echo "[
   467    {
   468      \"CommitDate\":\"$(get_date -50d)\",
   469      \"Files\":[
   470        {\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}]
   471    },
   472    {
   473      \"CommitDate\":\"$(get_date -40d)\",
   474      \"Files\":[
   475        {\"Filename\":\"file.dat\",\"Size\":${#content_commit2_failverify}, \"Data\":\"$content_commit2_failverify\"}]
   476    },
   477    {
   478      \"CommitDate\":\"$(get_date -35d)\",
   479      \"Files\":[
   480        {\"Filename\":\"file.dat\",\"Size\":${#content_commit3}, \"Data\":\"$content_commit3\"}]
   481    },
   482    {
   483      \"CommitDate\":\"$(get_date -25d)\",
   484      \"Files\":[
   485        {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}]
   486    }
   487    ]" | lfstest-testutils addcommits
   488  
   489    # push all so no unpushed reason to not prune
   490    git push origin master
   491  
   492    # set no recents so max ability to prune normally
   493    git config lfs.fetchrecentrefsdays 0
   494    git config lfs.fetchrecentremoterefs true
   495    git config lfs.fetchrecentcommitsdays 0
   496    git config lfs.pruneoffsetdays 1
   497  
   498    # confirm that it would prune with verify when no issues
   499    git lfs prune --dry-run --verify-remote --verbose 2>&1 | tee prune.log
   500    grep "4 local objects, 1 retained, 3 verified with remote" prune.log
   501    grep "3 files would be pruned" prune.log
   502    grep "$oid_commit3" prune.log
   503    grep "$oid_commit2_failverify" prune.log
   504    grep "$oid_commit1" prune.log
   505  
   506    # delete one file on the server to make the verify fail
   507    delete_server_object "remote_$reponame" "$oid_commit2_failverify"
   508    # this should now fail
   509    git lfs prune --verify-remote 2>&1 | tee prune.log
   510    grep "4 local objects, 1 retained, 2 verified with remote" prune.log
   511    grep "missing on remote:" prune.log
   512    grep "$oid_commit2_failverify" prune.log
   513    # Nothing should have been deleted
   514    assert_local_object "$oid_commit1" "${#content_commit1}"
   515    assert_local_object "$oid_commit2_failverify" "${#content_commit2_failverify}"
   516    assert_local_object "$oid_commit3" "${#content_commit3}"
   517  
   518    # Now test with the global option
   519    git config lfs.pruneverifyremotealways true
   520    # no verify arg but should be pulled from global
   521    git lfs prune 2>&1 | tee prune.log
   522    grep "4 local objects, 1 retained, 2 verified with remote" prune.log
   523    grep "missing on remote:" prune.log
   524    grep "$oid_commit2_failverify" prune.log
   525    # Nothing should have been deleted
   526    assert_local_object "$oid_commit1" "${#content_commit1}"
   527    assert_local_object "$oid_commit2_failverify" "${#content_commit2_failverify}"
   528    assert_local_object "$oid_commit3" "${#content_commit3}"
   529  
   530    # now try overriding the global option
   531    git lfs prune --no-verify-remote 2>&1 | tee prune.log
   532    grep "4 local objects, 1 retained" prune.log
   533    grep "Pruning 3 files" prune.log
   534    # should now have been deleted
   535    refute_local_object "$oid_commit1"
   536    refute_local_object "$oid_commit2_failverify"
   537    refute_local_object "$oid_commit3"
   538  
   539  )
   540  end_test
   541  
   542  begin_test "prune verify large numbers of refs"
   543  (
   544    set -e
   545  
   546    reponame="prune_verify_large"
   547    setup_remote_repo "remote_$reponame"
   548  
   549    clone_repo "remote_$reponame" "clone_$reponame"
   550  
   551    git lfs track "*.dat" 2>&1 | tee track.log
   552    grep "Tracking \"\*.dat\"" track.log
   553  
   554    content_head="HEAD content"
   555    content_commit1="Recent commit"
   556    content_oldcommit="Old content"
   557    oid_head=$(calc_oid "$content_head")
   558  
   559    # Add two recent commits that should not be pruned
   560    echo "[
   561    {
   562      \"CommitDate\":\"$(get_date -50d)\",
   563      \"Files\":[
   564        {\"Filename\":\"file.dat\",\"Size\":${#content_oldcommit}, \"Data\":\"$(uuidgen)\"}]
   565    },
   566    {
   567      \"CommitDate\":\"$(get_date -45d)\",
   568      \"Files\":[
   569        {\"Filename\":\"file.dat\",\"Size\":${#content_oldcommit}, \"Data\":\"$(uuidgen)\"}]
   570    },
   571    {
   572      \"CommitDate\":\"$(get_date -2d)\",
   573      \"Files\":[
   574        {\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}]
   575    },
   576    {
   577      \"CommitDate\":\"$(get_date -1d)\",
   578      \"Files\":[
   579        {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}]
   580    }
   581    ]" | lfstest-testutils addcommits
   582  
   583    # Generate a large number of refs to old commits make sure prune has a lot of data to read
   584    git checkout $(git log --pretty=oneline  master | tail -2 | awk '{print $1}' | head -1)
   585    for i in $(seq 0 1000); do
   586      git tag v$i
   587    done
   588    git checkout master
   589  
   590    # push all so no unpushed reason to not prune
   591    # git push origin master
   592  
   593    # set no recents so max ability to prune normally
   594    git config lfs.fetchrecentrefsdays 3
   595    git config lfs.fetchrecentremoterefs true
   596    git config lfs.fetchrecentcommitsdays 3
   597    git config lfs.pruneoffsetdays 3
   598  
   599    # confirm that prune does not hang
   600    git lfs prune --dry-run --verify-remote --verbose 2>&1 | tee prune.log
   601  
   602  )
   603  end_test