| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/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 | # Remember for something to be 'too old' it has to appear on the MINUS side |
| 30 | # of the diff outside the prune window, i.e. it's not when it was introduced |
| 31 | # but when it disappeared from relevance. That's why changes to old.dat on main |
| 32 | # from 7d ago are included even though the commit itself is outside of the window, |
| 33 | # that content of old.dat was relevant until it was removed with a commit, inside the window |
| 34 | # think of it as windows of relevance that overlap until the content is replaced |
| 35 | |
| 36 | # we also make sure we commit today on main so that the recent commits measured |
| 37 | # from latest commit on main tracks back from there |
| 38 | echo "[ |
| 39 | { |
| 40 | \"CommitDate\":\"$(get_date -20d)\", |
| 41 | \"Files\":[ |
| 42 | {\"Filename\":\"old.dat\",\"Size\":${#content_oldandpushed}, \"Data\":\"$content_oldandpushed\"}, |
| 43 | {\"Filename\":\"stillcurrent.dat\",\"Size\":${#content_oldandunchanged}, \"Data\":\"$content_oldandunchanged\"}] |
| 44 | }, |
| 45 | { |
| 46 | \"CommitDate\":\"$(get_date -7d)\", |
| 47 | \"Files\":[ |
| 48 | {\"Filename\":\"old.dat\",\"Size\":${#content_retain1}, \"Data\":\"$content_retain1\"}] |
| 49 | }, |
| 50 | { |
| 51 | \"CommitDate\":\"$(get_date -4d)\", |
| 52 | \"NewBranch\":\"branch_to_delete\", |
| 53 | \"Files\":[ |
| 54 | {\"Filename\":\"unreferenced.dat\",\"Size\":${#content_unreferenced}, \"Data\":\"$content_unreferenced\"}] |
| 55 | }, |
| 56 | { |
| 57 | \"ParentBranches\":[\"main\"], |
| 58 | \"Files\":[ |
| 59 | {\"Filename\":\"old.dat\",\"Size\":${#content_retain2}, \"Data\":\"$content_retain2\"}] |
| 60 | } |
| 61 | ]" | lfstest-testutils addcommits |
| 62 | |
| 63 | git push origin main |
| 64 | git branch -D branch_to_delete |
| 65 | |
| 66 | git config lfs.fetchrecentrefsdays 5 |
| 67 | git config lfs.fetchrecentremoterefs true |
| 68 | git config lfs.fetchrecentcommitsdays 3 |
| 69 | git config lfs.pruneoffsetdays 2 |
| 70 | |
| 71 | git lfs prune --dry-run --verbose 2>&1 | tee prune.log |
| 72 | |
| 73 | grep "5 local objects, 3 retained" prune.log |
| 74 | grep "2 files would be pruned" prune.log |
| 75 | grep "$oid_oldandpushed" prune.log |
| 76 | grep "$oid_unreferenced" prune.log |
| 77 | |
| 78 | assert_local_object "$oid_oldandpushed" "${#content_oldandpushed}" |
| 79 | assert_local_object "$oid_unreferenced" "${#content_unreferenced}" |
| 80 | git lfs prune |
| 81 | refute_local_object "$oid_oldandpushed" "${#content_oldandpushed}" |
| 82 | refute_local_object "$oid_unreferenced" "${#content_unreferenced}" |
| 83 | assert_local_object "$oid_oldandunchanged" "${#content_oldandunchanged}" |
| 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 | |
| 90 | git lfs prune --verbose 2>&1 | tee prune.log |
| 91 | grep "3 local objects, 2 retained" prune.log |
| 92 | grep "Deleting objects: 100% (1/1), done." prune.log |
| 93 | grep "$oid_retain1" prune.log |
| 94 | refute_local_object "$oid_retain1" |
| 95 | assert_local_object "$oid_retain2" "${#content_retain2}" |
| 96 | ) |
| 97 | end_test |
| 98 | |
| 99 | begin_test "prune all excluded paths" |
| 100 | ( |
| 101 | set -e |
| 102 | |
| 103 | reponame="prune_unref_old_exclude" |
| 104 | setup_remote_repo "remote_$reponame" |
| 105 | |
| 106 | clone_repo "remote_$reponame" "clone_$reponame" |
| 107 | |
| 108 | git lfs track "*.dat" 2>&1 | tee track.log |
| 109 | grep "Tracking \"\*.dat\"" track.log |
| 110 | |
| 111 | # generate content we'll use |
| 112 | content_oldandexcluded="To delete: pushed and too old and excluded by filter" |
| 113 | content_oldandunchanged="Keep: pushed and created a while ago, but still current" |
| 114 | content_prevandexcluded="To delete: pushed and in previous commit to HEAD but excluded by filter" |
| 115 | content_unreferencedandexcluded="To delete: unreferenced in deleted branch and pushed and excluded by filter" |
| 116 | content_includedandexcluded="Keep: pushed and both excluded by filter and included by another path" |
| 117 | content_excluded="To delete: pushed and in HEAD but excluded by filter" |
| 118 | oid_oldandexcluded=$(calc_oid "$content_oldandexcluded") |
| 119 | oid_oldandunchanged=$(calc_oid "$content_oldandunchanged") |
| 120 | oid_prevandexcluded=$(calc_oid "$content_prevandexcluded") |
| 121 | oid_unreferencedandexcluded=$(calc_oid "$content_unreferencedandexcluded") |
| 122 | oid_includedandexcluded=$(calc_oid "$content_includedandexcluded") |
| 123 | oid_excluded=$(calc_oid "$content_excluded") |
| 124 | |
| 125 | echo "[ |
| 126 | { |
| 127 | \"CommitDate\":\"$(get_date -20d)\", |
| 128 | \"Files\":[ |
| 129 | {\"Filename\":\"foo/oldandexcluded.dat\",\"Size\":${#content_oldandexcluded}, \"Data\":\"$content_oldandexcluded\"}, |
| 130 | {\"Filename\":\"stillcurrent.dat\",\"Size\":${#content_oldandunchanged}, \"Data\":\"$content_oldandunchanged\"}] |
| 131 | }, |
| 132 | { |
| 133 | \"CommitDate\":\"$(get_date -7d)\", |
| 134 | \"Files\":[ |
| 135 | {\"Filename\":\"foo/oldandexcluded.dat\",\"Size\":${#content_prevandexcluded}, \"Data\":\"$content_prevandexcluded\"}] |
| 136 | }, |
| 137 | { |
| 138 | \"CommitDate\":\"$(get_date -4d)\", |
| 139 | \"NewBranch\":\"branch_to_delete\", |
| 140 | \"Files\":[ |
| 141 | {\"Filename\":\"unreferenced.dat\",\"Size\":${#content_unreferencedandexcluded}, \"Data\":\"$content_unreferencedandexcluded\"}] |
| 142 | }, |
| 143 | { |
| 144 | \"ParentBranches\":[\"main\"], |
| 145 | \"Files\":[ |
| 146 | {\"Filename\":\"foo/unreferencedandexcluded.dat\",\"Size\":${#content_unreferencedandexcluded}, \"Data\":\"$content_unreferencedandexcluded\"}, |
| 147 | {\"Filename\":\"foo/includedandexcluded.dat\",\"Size\":${#content_includedandexcluded}, \"Data\":\"$content_includedandexcluded\"}, |
| 148 | {\"Filename\":\"included.dat\",\"Size\":${#content_includedandexcluded}, \"Data\":\"$content_includedandexcluded\"}, |
| 149 | {\"Filename\":\"foo/oldandexcluded.dat\",\"Size\":${#content_excluded}, \"Data\":\"$content_excluded\"}] |
| 150 | } |
| 151 | ]" | lfstest-testutils addcommits |
| 152 | |
| 153 | git push origin main |
| 154 | git branch -D branch_to_delete |
| 155 | |
| 156 | git config lfs.fetchrecentrefsdays 5 |
| 157 | git config lfs.fetchrecentremoterefs true |
| 158 | git config lfs.fetchrecentcommitsdays 3 |
| 159 | git config lfs.pruneoffsetdays 2 |
| 160 | |
| 161 | # We need to prevent MSYS from rewriting /foo into a Windows path. |
| 162 | MSYS_NO_PATHCONV=1 git config "lfs.fetchexclude" "/foo" |
| 163 | |
| 164 | git lfs prune --dry-run --verbose 2>&1 | tee prune.log |
| 165 | |
| 166 | grep "6 local objects, 2 retained" prune.log |
| 167 | grep "4 files would be pruned" prune.log |
| 168 | grep "$oid_oldandexcluded" prune.log |
| 169 | grep "$oid_prevandexcluded" prune.log |
| 170 | grep "$oid_unreferencedandexcluded" prune.log |
| 171 | grep "$oid_excluded" prune.log |
| 172 | |
| 173 | assert_local_object "$oid_oldandexcluded" "${#content_oldandexcluded}" |
| 174 | assert_local_object "$oid_prevandexcluded" "${#content_prevandexcluded}" |
| 175 | assert_local_object "$oid_unreferencedandexcluded" "${#content_unreferencedandexcluded}" |
| 176 | assert_local_object "$oid_excluded" "${#content_excluded}" |
| 177 | git lfs prune |
| 178 | refute_local_object "$oid_oldandexcluded" "${#content_oldandexcluded}" |
| 179 | assert_local_object "$oid_oldandunchanged" "${#content_oldandunchanged}" |
| 180 | refute_local_object "$oid_prevandexcluded" "${#content_prevandexcluded}" |
| 181 | refute_local_object "$oid_unreferencedandexcluded" "${#content_unreferencedandexcluded}" |
| 182 | assert_local_object "$oid_includedandexcluded" "${#content_includedandexcluded}" |
| 183 | refute_local_object "$oid_excluded" "${#content_excluded}" |
| 184 | ) |
| 185 | end_test |
| 186 | |
| 187 | begin_test "prune keep unpushed" |
| 188 | ( |
| 189 | set -e |
| 190 | |
| 191 | # need to set up many commits on each branch with old data so that would |
| 192 | # get deleted if it were not for unpushed status (heads would never be pruned but old changes would) |
| 193 | reponame="prune_keep_unpushed" |
| 194 | setup_remote_repo "remote_$reponame" |
| 195 | |
| 196 | clone_repo "remote_$reponame" "clone_$reponame" |
| 197 | |
| 198 | git lfs track "*.dat" 2>&1 | tee track.log |
| 199 | grep "Tracking \"\*.dat\"" track.log |
| 200 | |
| 201 | content_keepunpushedhead1="Keep: unpushed HEAD 1" |
| 202 | content_keepunpushedhead2="Keep: unpushed HEAD 2" |
| 203 | content_keepunpushedhead3="Keep: unpushed HEAD 3" |
| 204 | content_keepunpushedbranch1="Keep: unpushed second branch 1" |
| 205 | content_keepunpushedbranch2="Keep: unpushed second branch 2" |
| 206 | content_keepunpushedbranch3="Keep: unpushed second branch 3" |
| 207 | content_keepunpushedandexcludedbranch1="Keep: unpushed second branch 1 excluded by filter" |
| 208 | content_keepunpushedandexcludedbranch2="Keep: unpushed second branch 2 excluded by filter" |
| 209 | content_keepunpushedandexcludedbranch3="Keep: unpushed second branch 3 excluded by filter" |
| 210 | content_keepunpushedtag1="Keep: unpushed tag only 1" |
| 211 | content_keepunpushedtag2="Keep: unpushed tag only 2" |
| 212 | content_keepunpushedtag3="Keep: unpushed tag only 3" |
| 213 | oid_keepunpushedhead1=$(calc_oid "$content_keepunpushedhead1") |
| 214 | oid_keepunpushedhead2=$(calc_oid "$content_keepunpushedhead2") |
| 215 | oid_keepunpushedhead3=$(calc_oid "$content_keepunpushedhead3") |
| 216 | oid_keepunpushedbranch1=$(calc_oid "$content_keepunpushedbranch1") |
| 217 | oid_keepunpushedbranch2=$(calc_oid "$content_keepunpushedbranch2") |
| 218 | oid_keepunpushedbranch3=$(calc_oid "$content_keepunpushedbranch3") |
| 219 | oid_keepunpushedandexcludedbranch1=$(calc_oid "$content_keepunpushedandexcludedbranch1") |
| 220 | oid_keepunpushedandexcludedbranch2=$(calc_oid "$content_keepunpushedandexcludedbranch2") |
| 221 | oid_keepunpushedandexcludedbranch3=$(calc_oid "$content_keepunpushedandexcludedbranch3") |
| 222 | oid_keepunpushedtag1=$(calc_oid "$content_keepunpushedtag1") |
| 223 | oid_keepunpushedtag2=$(calc_oid "$content_keepunpushedtag2") |
| 224 | oid_keepunpushedtag3=$(calc_oid "$content_keepunpushedtag3") |
| 225 | |
| 226 | echo "[ |
| 227 | { |
| 228 | \"CommitDate\":\"$(get_date -40d)\", |
| 229 | \"Files\":[ |
| 230 | {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedhead1}, \"Data\":\"$content_keepunpushedhead1\"}] |
| 231 | }, |
| 232 | { |
| 233 | \"CommitDate\":\"$(get_date -31d)\", |
| 234 | \"ParentBranches\":[\"main\"], |
| 235 | \"NewBranch\":\"branch_unpushed\", |
| 236 | \"Files\":[ |
| 237 | {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedbranch1}, \"Data\":\"$content_keepunpushedbranch1\"}, |
| 238 | {\"Filename\":\"foo/file.dat\",\"Size\":${#content_keepunpushedandexcludedbranch1}, \"Data\":\"$content_keepunpushedandexcludedbranch1\"}] |
| 239 | }, |
| 240 | { |
| 241 | \"CommitDate\":\"$(get_date -16d)\", |
| 242 | \"Files\":[ |
| 243 | {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedbranch2}, \"Data\":\"$content_keepunpushedbranch2\"}, |
| 244 | {\"Filename\":\"foo/file.dat\",\"Size\":${#content_keepunpushedandexcludedbranch2}, \"Data\":\"$content_keepunpushedandexcludedbranch2\"}] |
| 245 | }, |
| 246 | { |
| 247 | \"CommitDate\":\"$(get_date -2d)\", |
| 248 | \"Files\":[ |
| 249 | {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedbranch3}, \"Data\":\"$content_keepunpushedbranch3\"}, |
| 250 | {\"Filename\":\"foo/file.dat\",\"Size\":${#content_keepunpushedandexcludedbranch3}, \"Data\":\"$content_keepunpushedandexcludedbranch3\"}] |
| 251 | }, |
| 252 | { |
| 253 | \"CommitDate\":\"$(get_date -31d)\", |
| 254 | \"ParentBranches\":[\"main\"], |
| 255 | \"NewBranch\":\"branch_unpushed_tagged_only\", |
| 256 | \"Files\":[ |
| 257 | {\"Filename\":\"file2.dat\",\"Size\":${#content_keepunpushedtag1}, \"Data\":\"$content_keepunpushedtag1\"}] |
| 258 | }, |
| 259 | { |
| 260 | \"CommitDate\":\"$(get_date -16d)\", |
| 261 | \"Files\":[ |
| 262 | {\"Filename\":\"file2.dat\",\"Size\":${#content_keepunpushedtag2}, \"Data\":\"$content_keepunpushedtag2\"}] |
| 263 | }, |
| 264 | { |
| 265 | \"CommitDate\":\"$(get_date -2d)\", |
| 266 | \"Tags\":[\"tag_unpushed\"], |
| 267 | \"Files\":[ |
| 268 | {\"Filename\":\"file2.dat\",\"Size\":${#content_keepunpushedtag3}, \"Data\":\"$content_keepunpushedtag3\"}] |
| 269 | }, |
| 270 | { |
| 271 | \"CommitDate\":\"$(get_date -21d)\", |
| 272 | \"ParentBranches\":[\"main\"], |
| 273 | \"Files\":[ |
| 274 | {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedhead2}, \"Data\":\"$content_keepunpushedhead2\"}] |
| 275 | }, |
| 276 | { |
| 277 | \"CommitDate\":\"$(get_date -0d)\", |
| 278 | \"Files\":[ |
| 279 | {\"Filename\":\"file.dat\",\"Size\":${#content_keepunpushedhead3}, \"Data\":\"$content_keepunpushedhead3\"}] |
| 280 | } |
| 281 | ]" | lfstest-testutils addcommits |
| 282 | |
| 283 | git config lfs.fetchrecentrefsdays 5 |
| 284 | git config lfs.fetchrecentremoterefs true |
| 285 | git config lfs.fetchrecentcommitsdays 0 # only keep AT refs, no recents |
| 286 | git config lfs.pruneoffsetdays 2 |
| 287 | |
| 288 | # We need to prevent MSYS from rewriting /foo into a Windows path. |
| 289 | MSYS_NO_PATHCONV=1 git config "lfs.fetchexclude" "/foo" |
| 290 | |
| 291 | # force color codes in git diff meta-information |
| 292 | git config color.diff always |
| 293 | |
| 294 | git branch -D branch_unpushed_tagged_only |
| 295 | |
| 296 | git lfs prune |
| 297 | |
| 298 | # Now push main and show that only older versions on main will be removed. |
| 299 | git push origin main |
| 300 | |
| 301 | git lfs prune --verbose 2>&1 | tee prune.log |
| 302 | grep "12 local objects, 10 retained" prune.log |
| 303 | grep "Deleting objects: 100% (2/2), done." prune.log |
| 304 | grep "$oid_keepunpushedhead1" prune.log |
| 305 | grep "$oid_keepunpushedhead2" prune.log |
| 306 | refute_local_object "$oid_keepunpushedhead1" |
| 307 | refute_local_object "$oid_keepunpushedhead2" |
| 308 | |
| 309 | # Merge the unpushed branch and tag, delete them, and then push main. |
| 310 | # Resolve conflicts by taking other branch. |
| 311 | git merge -Xtheirs branch_unpushed |
| 312 | git merge tag_unpushed |
| 313 | git branch -D branch_unpushed |
| 314 | git tag -d tag_unpushed |
| 315 | git push origin main |
| 316 | |
| 317 | # Now make sure we purged all the intermediate commits but also make sure |
| 318 | # they are on the remote. |
| 319 | git lfs prune --verbose 2>&1 | tee prune.log |
| 320 | grep "10 local objects, 2 retained" prune.log |
| 321 | grep "Deleting objects: 100% (8/8), done." prune.log |
| 322 | grep "$oid_keepunpushedbranch1" prune.log |
| 323 | grep "$oid_keepunpushedbranch2" prune.log |
| 324 | grep "$oid_keepunpushedandexcludedbranch1" prune.log |
| 325 | grep "$oid_keepunpushedandexcludedbranch2" prune.log |
| 326 | # This is in the new HEAD and would be retained except that it is also |
| 327 | # excluded by the filter and has been pushed, so it should have been purged. |
| 328 | grep "$oid_keepunpushedandexcludedbranch3" prune.log |
| 329 | grep "$oid_keepunpushedtag1" prune.log |
| 330 | grep "$oid_keepunpushedtag2" prune.log |
| 331 | grep "$oid_keepunpushedhead3" prune.log |
| 332 | refute_local_object "$oid_keepunpushedbranch1" |
| 333 | refute_local_object "$oid_keepunpushedbranch2" |
| 334 | refute_local_object "$oid_keepunpushedandexcludedbranch1" |
| 335 | refute_local_object "$oid_keepunpushedandexcludedbranch2" |
| 336 | # This is in the new HEAD and would be retained except that it is also |
| 337 | # excluded by the filter and has been pushed, so it should have been purged. |
| 338 | refute_local_object "$oid_keepunpushedandexcludedbranch3" |
| 339 | refute_local_object "$oid_keepunpushedtag1" |
| 340 | refute_local_object "$oid_keepunpushedtag2" |
| 341 | # We used -Xtheirs when merging the branch so the old HEAD is now obsolete. |
| 342 | refute_local_object "$oid_keepunpushedhead3" |
| 343 | assert_server_object "remote_$reponame" "$oid_keepunpushedbranch1" |
| 344 | assert_server_object "remote_$reponame" "$oid_keepunpushedbranch2" |
| 345 | assert_server_object "remote_$reponame" "$oid_keepunpushedandexcludedbranch1" |
| 346 | assert_server_object "remote_$reponame" "$oid_keepunpushedandexcludedbranch2" |
| 347 | assert_server_object "remote_$reponame" "$oid_keepunpushedandexcludedbranch3" |
| 348 | assert_server_object "remote_$reponame" "$oid_keepunpushedtag1" |
| 349 | assert_server_object "remote_$reponame" "$oid_keepunpushedtag2" |
| 350 | assert_server_object "remote_$reponame" "$oid_keepunpushedhead3" |
| 351 | ) |
| 352 | end_test |
| 353 | |
| 354 | begin_test "prune keep recent" |
| 355 | ( |
| 356 | set -e |
| 357 | |
| 358 | reponame="prune_recent" |
| 359 | setup_remote_repo "remote_$reponame" |
| 360 | |
| 361 | clone_repo "remote_$reponame" "clone_$reponame" |
| 362 | |
| 363 | git lfs track "*.dat" 2>&1 | tee track.log |
| 364 | grep "Tracking \"\*.dat\"" track.log |
| 365 | |
| 366 | content_keephead="Keep: HEAD" |
| 367 | content_keeprecentbranch1tip="Keep: Recent branch 1 tip" |
| 368 | content_keeprecentbranch2tip="Keep: Recent branch 2 tip" |
| 369 | content_keeprecentcommithead="Keep: Recent commit on HEAD" |
| 370 | content_keeprecentcommitbranch1="Keep: Recent commit on recent branch 1" |
| 371 | content_keeprecentcommitbranch2="Keep: Recent commit on recent branch 2" |
| 372 | content_prunecommitoldbranch1="Prune: old commit on old branch" |
| 373 | content_prunecommitoldbranch2="Prune: old branch tip" |
| 374 | content_prunecommitbranch1="Prune: old commit on recent branch 1" |
| 375 | content_prunecommitbranch2="Prune: old commit on recent branch 2" |
| 376 | content_prunecommithead="Prune: old commit on HEAD" |
| 377 | oid_keephead=$(calc_oid "$content_keephead") |
| 378 | oid_keeprecentbranch1tip=$(calc_oid "$content_keeprecentbranch1tip") |
| 379 | oid_keeprecentbranch2tip=$(calc_oid "$content_keeprecentbranch2tip") |
| 380 | oid_keeprecentcommithead=$(calc_oid "$content_keeprecentcommithead") |
| 381 | oid_keeprecentcommitbranch1=$(calc_oid "$content_keeprecentcommitbranch1") |
| 382 | oid_keeprecentcommitbranch2=$(calc_oid "$content_keeprecentcommitbranch2") |
| 383 | oid_prunecommitoldbranch=$(calc_oid "$content_prunecommitoldbranch1") |
| 384 | oid_prunecommitoldbranch2=$(calc_oid "$content_prunecommitoldbranch2") |
| 385 | oid_prunecommitbranch1=$(calc_oid "$content_prunecommitbranch1") |
| 386 | oid_prunecommitbranch2=$(calc_oid "$content_prunecommitbranch2") |
| 387 | oid_prunecommithead=$(calc_oid "$content_prunecommithead") |
| 388 | |
| 389 | # use a single file so each commit supersedes the last, if different files |
| 390 | # then history becomes harder to track |
| 391 | # Also note that when considering 'recent' when editing a single file, it means |
| 392 | # that the snapshot state overlapped; so the latest commit *before* the day |
| 393 | # that you're looking at, not just the commits on/after. |
| 394 | echo "[ |
| 395 | { |
| 396 | \"CommitDate\":\"$(get_date -50d)\", |
| 397 | \"Files\":[ |
| 398 | {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommithead}, \"Data\":\"$content_prunecommithead\"}] |
| 399 | }, |
| 400 | { |
| 401 | \"CommitDate\":\"$(get_date -30d)\", |
| 402 | \"Files\":[ |
| 403 | {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentcommithead}, \"Data\":\"$content_keeprecentcommithead\"}] |
| 404 | }, |
| 405 | { |
| 406 | \"CommitDate\":\"$(get_date -8d)\", |
| 407 | \"NewBranch\":\"branch_old\", |
| 408 | \"Files\":[ |
| 409 | {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommitoldbranch1}, \"Data\":\"$content_prunecommitoldbranch1\"}] |
| 410 | }, |
| 411 | { |
| 412 | \"CommitDate\":\"$(get_date -7d)\", |
| 413 | \"Files\":[ |
| 414 | {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommitoldbranch2}, \"Data\":\"$content_prunecommitoldbranch2\"}] |
| 415 | }, |
| 416 | { |
| 417 | \"CommitDate\":\"$(get_date -9d)\", |
| 418 | \"ParentBranches\":[\"main\"], |
| 419 | \"NewBranch\":\"branch1\", |
| 420 | \"Files\":[ |
| 421 | {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommitbranch1}, \"Data\":\"$content_prunecommitbranch1\"}] |
| 422 | }, |
| 423 | { |
| 424 | \"CommitDate\":\"$(get_date -8d)\", |
| 425 | \"Files\":[ |
| 426 | {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentcommitbranch1}, \"Data\":\"$content_keeprecentcommitbranch1\"}] |
| 427 | }, |
| 428 | { |
| 429 | \"CommitDate\":\"$(get_date -5d)\", |
| 430 | \"Files\":[ |
| 431 | {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentbranch1tip}, \"Data\":\"$content_keeprecentbranch1tip\"}] |
| 432 | }, |
| 433 | { |
| 434 | \"CommitDate\":\"$(get_date -17d)\", |
| 435 | \"ParentBranches\":[\"main\"], |
| 436 | \"NewBranch\":\"branch2\", |
| 437 | \"Files\":[ |
| 438 | {\"Filename\":\"file.dat\",\"Size\":${#content_prunecommitbranch2}, \"Data\":\"$content_prunecommitbranch2\"}] |
| 439 | }, |
| 440 | { |
| 441 | \"CommitDate\":\"$(get_date -10d)\", |
| 442 | \"Files\":[ |
| 443 | {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentcommitbranch2}, \"Data\":\"$content_keeprecentcommitbranch2\"}] |
| 444 | }, |
| 445 | { |
| 446 | \"CommitDate\":\"$(get_date -2d)\", |
| 447 | \"Files\":[ |
| 448 | {\"Filename\":\"file.dat\",\"Size\":${#content_keeprecentbranch2tip}, \"Data\":\"$content_keeprecentbranch2tip\"}] |
| 449 | }, |
| 450 | { |
| 451 | \"CommitDate\":\"$(get_date -1d)\", |
| 452 | \"ParentBranches\":[\"main\"], |
| 453 | \"Files\":[ |
| 454 | {\"Filename\":\"file.dat\",\"Size\":${#content_keephead}, \"Data\":\"$content_keephead\"}] |
| 455 | } |
| 456 | ]" | lfstest-testutils addcommits |
| 457 | |
| 458 | # keep refs for 6 days & any prev commit that overlaps 2 days before tip (recent + offset) |
| 459 | git config lfs.fetchrecentrefsdays 5 |
| 460 | git config lfs.fetchrecentremoterefs true |
| 461 | git config lfs.fetchrecentcommitsdays 1 |
| 462 | git config lfs.pruneoffsetdays 1 |
| 463 | |
| 464 | # force color codes in git diff meta-information |
| 465 | git config color.diff always |
| 466 | |
| 467 | # push everything so that's not a reason to retain |
| 468 | git push origin main:main branch_old:branch_old branch1:branch1 branch2:branch2 |
| 469 | |
| 470 | git lfs prune --verbose 2>&1 | tee prune.log |
| 471 | grep "11 local objects, 6 retained, done." prune.log |
| 472 | grep "Deleting objects: 100% (5/5), done." prune.log |
| 473 | grep "$oid_prunecommitoldbranch" prune.log |
| 474 | grep "$oid_prunecommitoldbranch2" prune.log |
| 475 | grep "$oid_prunecommitbranch1" prune.log |
| 476 | grep "$oid_prunecommitbranch2" prune.log |
| 477 | grep "$oid_prunecommithead" prune.log |
| 478 | |
| 479 | refute_local_object "$oid_prunecommitoldbranch" |
| 480 | refute_local_object "$oid_prunecommitoldbranch2" |
| 481 | refute_local_object "$oid_prunecommitbranch1" |
| 482 | refute_local_object "$oid_prunecommitbranch2" |
| 483 | refute_local_object "$oid_prunecommithead" |
| 484 | assert_local_object "$oid_keephead" "${#content_keephead}" |
| 485 | assert_local_object "$oid_keeprecentbranch1tip" "${#content_keeprecentbranch1tip}" |
| 486 | assert_local_object "$oid_keeprecentbranch2tip" "${#content_keeprecentbranch2tip}" |
| 487 | assert_local_object "$oid_keeprecentcommithead" "${#content_keeprecentcommithead}" |
| 488 | assert_local_object "$oid_keeprecentcommitbranch1" "${#content_keeprecentcommitbranch1}" |
| 489 | assert_local_object "$oid_keeprecentcommitbranch2" "${#content_keeprecentcommitbranch2}" |
| 490 | |
| 491 | # now don't include any recent commits in fetch & hence don't retain |
| 492 | # still retain tips of branches |
| 493 | git config lfs.fetchrecentcommitsdays 0 |
| 494 | git lfs prune --verbose 2>&1 | tee prune.log |
| 495 | grep "6 local objects, 3 retained, done." prune.log |
| 496 | grep "Deleting objects: 100% (3/3), done." prune.log |
| 497 | assert_local_object "$oid_keephead" "${#content_keephead}" |
| 498 | assert_local_object "$oid_keeprecentbranch1tip" "${#content_keeprecentbranch1tip}" |
| 499 | assert_local_object "$oid_keeprecentbranch2tip" "${#content_keeprecentbranch2tip}" |
| 500 | refute_local_object "$oid_keeprecentcommithead" |
| 501 | refute_local_object "$oid_keeprecentcommitbranch1" |
| 502 | refute_local_object "$oid_keeprecentcommitbranch2" |
| 503 | |
| 504 | # now don't include any recent refs at all, only keep HEAD |
| 505 | git config lfs.fetchrecentrefsdays 0 |
| 506 | git lfs prune --verbose 2>&1 | tee prune.log |
| 507 | grep "3 local objects, 1 retained, done." prune.log |
| 508 | grep "Deleting objects: 100% (2/2), done." prune.log |
| 509 | assert_local_object "$oid_keephead" "${#content_keephead}" |
| 510 | refute_local_object "$oid_keeprecentbranch1tip" |
| 511 | refute_local_object "$oid_keeprecentbranch2tip" |
| 512 | ) |
| 513 | end_test |
| 514 | |
| 515 | begin_test "prune remote tests" |
| 516 | ( |
| 517 | set -e |
| 518 | |
| 519 | reponame="prune_no_or_nonorigin_remote" |
| 520 | git init "$reponame" |
| 521 | cd "$reponame" |
| 522 | |
| 523 | git lfs track "*.dat" 2>&1 | tee track.log |
| 524 | grep "Tracking \"\*.dat\"" track.log |
| 525 | |
| 526 | echo "[ |
| 527 | { |
| 528 | \"CommitDate\":\"$(get_date -50d)\", |
| 529 | \"Files\":[ |
| 530 | {\"Filename\":\"file.dat\",\"Size\":30}] |
| 531 | }, |
| 532 | { |
| 533 | \"CommitDate\":\"$(get_date -40d)\", |
| 534 | \"Files\":[ |
| 535 | {\"Filename\":\"file.dat\",\"Size\":28}] |
| 536 | }, |
| 537 | { |
| 538 | \"CommitDate\":\"$(get_date -35d)\", |
| 539 | \"Files\":[ |
| 540 | {\"Filename\":\"file.dat\",\"Size\":37}] |
| 541 | }, |
| 542 | { |
| 543 | \"CommitDate\":\"$(get_date -25d)\", |
| 544 | \"Files\":[ |
| 545 | {\"Filename\":\"file.dat\",\"Size\":42}] |
| 546 | } |
| 547 | ]" | lfstest-testutils addcommits |
| 548 | |
| 549 | # set no recents so max ability to prune normally |
| 550 | git config lfs.fetchrecentrefsdays 0 |
| 551 | git config lfs.fetchrecentremoterefs true |
| 552 | git config lfs.fetchrecentcommitsdays 0 |
| 553 | git config lfs.pruneoffsetdays 1 |
| 554 | |
| 555 | # can never prune with no remote |
| 556 | git lfs prune --verbose 2>&1 | tee prune.log |
| 557 | grep "4 local objects, 4 retained, done." prune.log |
| 558 | |
| 559 | |
| 560 | # also make sure nothing is pruned when remote is not origin |
| 561 | # create 2 remotes, neither of which is called origin & push to both |
| 562 | setup_remote_repo "remote1_$reponame" |
| 563 | setup_remote_repo "remote2_$reponame" |
| 564 | cd "$TRASHDIR/$reponame" |
| 565 | git remote add not_origin "$GITSERVER/remote1_$reponame" |
| 566 | git push not_origin main |
| 567 | |
| 568 | git lfs prune --verbose 2>&1 | tee prune.log |
| 569 | grep "4 local objects, 4 retained, done." prune.log |
| 570 | |
| 571 | # now set the prune remote to be not_origin, should now prune |
| 572 | # do a dry run so we can also verify |
| 573 | git config lfs.pruneremotetocheck not_origin |
| 574 | |
| 575 | git lfs prune --verbose --dry-run 2>&1 | tee prune.log |
| 576 | grep "4 local objects, 1 retained, done." prune.log |
| 577 | grep "3 files would be pruned" prune.log |
| 578 | ) |
| 579 | end_test |
| 580 | |
| 581 | begin_test "prune verify" |
| 582 | ( |
| 583 | set -e |
| 584 | |
| 585 | reponame="prune_verify" |
| 586 | setup_remote_repo "remote_$reponame" |
| 587 | |
| 588 | clone_repo "remote_$reponame" "clone_$reponame" |
| 589 | |
| 590 | git lfs track "*.dat" 2>&1 | tee track.log |
| 591 | grep "Tracking \"\*.dat\"" track.log |
| 592 | |
| 593 | content_head="HEAD content" |
| 594 | content_commit3="Content for commit 3 (prune)" |
| 595 | content_commit2_failverify="Content for commit 2 (prune - fail verify)" |
| 596 | content_commit1="Content for commit 1 (prune)" |
| 597 | oid_head=$(calc_oid "$content_head") |
| 598 | oid_commit3=$(calc_oid "$content_commit3") |
| 599 | oid_commit2_failverify=$(calc_oid "$content_commit2_failverify") |
| 600 | oid_commit1=$(calc_oid "$content_commit1") |
| 601 | |
| 602 | echo "[ |
| 603 | { |
| 604 | \"CommitDate\":\"$(get_date -50d)\", |
| 605 | \"Files\":[ |
| 606 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}] |
| 607 | }, |
| 608 | { |
| 609 | \"CommitDate\":\"$(get_date -40d)\", |
| 610 | \"Files\":[ |
| 611 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit2_failverify}, \"Data\":\"$content_commit2_failverify\"}] |
| 612 | }, |
| 613 | { |
| 614 | \"CommitDate\":\"$(get_date -35d)\", |
| 615 | \"Files\":[ |
| 616 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit3}, \"Data\":\"$content_commit3\"}] |
| 617 | }, |
| 618 | { |
| 619 | \"CommitDate\":\"$(get_date -25d)\", |
| 620 | \"Files\":[ |
| 621 | {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}] |
| 622 | } |
| 623 | ]" | lfstest-testutils addcommits |
| 624 | |
| 625 | # push all so no unpushed reason to not prune |
| 626 | git push origin main |
| 627 | |
| 628 | # set no recents so max ability to prune normally |
| 629 | git config lfs.fetchrecentrefsdays 0 |
| 630 | git config lfs.fetchrecentremoterefs true |
| 631 | git config lfs.fetchrecentcommitsdays 0 |
| 632 | git config lfs.pruneoffsetdays 1 |
| 633 | |
| 634 | # confirm that it would prune with verify when no issues |
| 635 | git lfs prune --dry-run --verify-remote --verbose 2>&1 | tee prune.log |
| 636 | grep "4 local objects, 1 retained, 3 verified with remote, done." prune.log |
| 637 | grep "3 files would be pruned" prune.log |
| 638 | grep "$oid_commit3" prune.log |
| 639 | grep "$oid_commit2_failverify" prune.log |
| 640 | grep "$oid_commit1" prune.log |
| 641 | |
| 642 | # delete one file on the server to make the verify fail |
| 643 | delete_server_object "remote_$reponame" "$oid_commit2_failverify" |
| 644 | # this should now fail |
| 645 | git lfs prune --verify-remote 2>&1 | tee prune.log |
| 646 | grep "4 local objects, 1 retained, 2 verified with remote, 1 not on remote, done." prune.log |
| 647 | grep "missing on remote:" prune.log |
| 648 | grep "$oid_commit2_failverify" prune.log |
| 649 | # Nothing should have been deleted |
| 650 | assert_local_object "$oid_commit1" "${#content_commit1}" |
| 651 | assert_local_object "$oid_commit2_failverify" "${#content_commit2_failverify}" |
| 652 | assert_local_object "$oid_commit3" "${#content_commit3}" |
| 653 | |
| 654 | # Now test with the global option |
| 655 | git config lfs.pruneverifyremotealways true |
| 656 | # no verify arg but should be pulled from global |
| 657 | git lfs prune 2>&1 | tee prune.log |
| 658 | grep "4 local objects, 1 retained, 2 verified with remote, 1 not on remote, done." prune.log |
| 659 | grep "missing on remote:" prune.log |
| 660 | grep "$oid_commit2_failverify" prune.log |
| 661 | # Nothing should have been deleted |
| 662 | assert_local_object "$oid_commit1" "${#content_commit1}" |
| 663 | assert_local_object "$oid_commit2_failverify" "${#content_commit2_failverify}" |
| 664 | assert_local_object "$oid_commit3" "${#content_commit3}" |
| 665 | |
| 666 | # --when-unverified=continue we would prune verified objects but skip unverified objects |
| 667 | git lfs prune --when-unverified=continue --dry-run --verbose 2>&1 | tee prune.log |
| 668 | grep "4 local objects, 1 retained, 2 verified with remote, 1 not on remote, done." prune.log |
| 669 | grep "2 files would be pruned" prune.log |
| 670 | grep "$oid_commit1" prune.log |
| 671 | grep "$oid_commit3" prune.log |
| 672 | |
| 673 | # now try overriding the global option |
| 674 | git lfs prune --no-verify-remote 2>&1 | tee prune.log |
| 675 | grep "4 local objects, 1 retained, done." prune.log |
| 676 | grep "Deleting objects: 100% (3/3), done." prune.log |
| 677 | # should now have been deleted |
| 678 | refute_local_object "$oid_commit1" |
| 679 | refute_local_object "$oid_commit2_failverify" |
| 680 | refute_local_object "$oid_commit3" |
| 681 | ) |
| 682 | end_test |
| 683 | |
| 684 | begin_test "prune verify large numbers of refs" |
| 685 | ( |
| 686 | set -e |
| 687 | |
| 688 | reponame="prune_verify_large" |
| 689 | setup_remote_repo "remote_$reponame" |
| 690 | |
| 691 | clone_repo "remote_$reponame" "clone_$reponame" |
| 692 | |
| 693 | git lfs track "*.dat" 2>&1 | tee track.log |
| 694 | grep "Tracking \"\*.dat\"" track.log |
| 695 | |
| 696 | content_head="HEAD content" |
| 697 | content_commit1="Recent commit" |
| 698 | content_oldcommit1="Old content $(lfstest-genrandom --base64 40)" |
| 699 | content_oldcommit2="Old content $(lfstest-genrandom --base64 40)" |
| 700 | oid_head=$(calc_oid "$content_head") |
| 701 | |
| 702 | # Add two recent commits that should not be pruned |
| 703 | echo "[ |
| 704 | { |
| 705 | \"CommitDate\":\"$(get_date -50d)\", |
| 706 | \"Files\":[ |
| 707 | {\"Filename\":\"file.dat\",\"Size\":${#content_oldcommit1}, \"Data\":\"$content_oldcommit1\"}] |
| 708 | }, |
| 709 | { |
| 710 | \"CommitDate\":\"$(get_date -45d)\", |
| 711 | \"Files\":[ |
| 712 | {\"Filename\":\"file.dat\",\"Size\":${#content_oldcommit2}, \"Data\":\"$content_oldcommit2\"}] |
| 713 | }, |
| 714 | { |
| 715 | \"CommitDate\":\"$(get_date -2d)\", |
| 716 | \"Files\":[ |
| 717 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}] |
| 718 | }, |
| 719 | { |
| 720 | \"CommitDate\":\"$(get_date -1d)\", |
| 721 | \"Files\":[ |
| 722 | {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}] |
| 723 | } |
| 724 | ]" | lfstest-testutils addcommits |
| 725 | |
| 726 | # Generate a large number of refs to old commits make sure prune has a lot of data to read |
| 727 | git checkout $(git log --pretty=oneline main | tail -2 | awk '{print $1}' | head -1) |
| 728 | for i in $(seq 0 1000); do |
| 729 | git tag v$i |
| 730 | done |
| 731 | git checkout main |
| 732 | |
| 733 | # push all so no unpushed reason to not prune |
| 734 | # git push origin main |
| 735 | |
| 736 | # set no recents so max ability to prune normally |
| 737 | git config lfs.fetchrecentrefsdays 3 |
| 738 | git config lfs.fetchrecentremoterefs true |
| 739 | git config lfs.fetchrecentcommitsdays 3 |
| 740 | git config lfs.pruneoffsetdays 3 |
| 741 | |
| 742 | # confirm that prune does not hang |
| 743 | git lfs prune --dry-run --verify-remote --verbose 2>&1 | tee prune.log |
| 744 | ) |
| 745 | end_test |
| 746 | |
| 747 | begin_test "prune unreachable" |
| 748 | ( |
| 749 | set -e |
| 750 | |
| 751 | reponame="prune_unreachable" |
| 752 | setup_remote_repo "remote_$reponame" |
| 753 | |
| 754 | clone_repo "remote_$reponame" "clone_$reponame" |
| 755 | |
| 756 | git lfs track "*.dat" 2>&1 | tee track.log |
| 757 | grep "Tracking \"\*.dat\"" track.log |
| 758 | |
| 759 | content_head="HEAD content" |
| 760 | content_orphan="orphan content (not pruned)" |
| 761 | content_commit3="Content for commit 3 (prune)" |
| 762 | content_commit2="Content for commit 2" |
| 763 | content_commit1="Content for commit 1 (prune)" |
| 764 | oid_head=$(calc_oid "$content_head") |
| 765 | oid_orphan=$(calc_oid "$content_orphan") |
| 766 | oid_commit3=$(calc_oid "$content_commit3") |
| 767 | oid_commit2=$(calc_oid "$content_commit2") |
| 768 | oid_commit1=$(calc_oid "$content_commit1") |
| 769 | |
| 770 | echo "[ |
| 771 | { |
| 772 | \"CommitDate\":\"$(get_date -50d)\", |
| 773 | \"Files\":[ |
| 774 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit1}, \"Data\":\"$content_commit1\"}] |
| 775 | }, |
| 776 | { |
| 777 | \"CommitDate\":\"$(get_date -40d)\", |
| 778 | \"Files\":[ |
| 779 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit2}, \"Data\":\"$content_commit2\"}] |
| 780 | }, |
| 781 | { |
| 782 | \"CommitDate\":\"$(get_date -35d)\", |
| 783 | \"Files\":[ |
| 784 | {\"Filename\":\"file.dat\",\"Size\":${#content_commit3}, \"Data\":\"$content_commit3\"}] |
| 785 | }, |
| 786 | { |
| 787 | \"CommitDate\":\"$(get_date -25d)\", |
| 788 | \"Files\":[ |
| 789 | {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}] |
| 790 | } |
| 791 | ]" | lfstest-testutils addcommits |
| 792 | |
| 793 | # push all so no unpushed reason to not prune |
| 794 | git push origin main |
| 795 | |
| 796 | # set no recents so max ability to prune normally |
| 797 | git config lfs.fetchrecentrefsdays 0 |
| 798 | git config lfs.fetchrecentremoterefs true |
| 799 | git config lfs.fetchrecentcommitsdays 0 |
| 800 | git config lfs.pruneoffsetdays 1 |
| 801 | |
| 802 | # add one file to the index and then remove it to see if unreachable files are pruned |
| 803 | echo -n "$content_orphan" > file.dat |
| 804 | git add file.dat |
| 805 | git reset file.dat |
| 806 | |
| 807 | # confirm that it would prune without --verify-unreachable |
| 808 | git lfs prune --dry-run --verify-remote --verbose 2>&1 | tee prune.log |
| 809 | grep "5 local objects, 1 retained, 3 verified with remote, done." prune.log |
| 810 | grep "4 files would be pruned" prune.log |
| 811 | grep "$oid_commit3" prune.log |
| 812 | grep "$oid_commit2" prune.log |
| 813 | grep "$oid_commit1" prune.log |
| 814 | grep "$oid_orphan" prune.log |
| 815 | |
| 816 | # this should now halt as one file cannot be verified |
| 817 | git lfs prune --verify-remote --verify-unreachable 2>&1 | tee prune.log |
| 818 | grep "5 local objects, 1 retained, 3 verified with remote, 1 not on remote, done." prune.log |
| 819 | grep "missing on remote:" prune.log |
| 820 | grep "$oid_orphan" prune.log |
| 821 | |
| 822 | # No files should have been deleted |
| 823 | assert_local_object "$oid_head" "${#content_head}" |
| 824 | assert_local_object "$oid_commit1" "${#content_commit1}" |
| 825 | assert_local_object "$oid_commit2" "${#content_commit2}" |
| 826 | assert_local_object "$oid_commit3" "${#content_commit3}" |
| 827 | assert_local_object "$oid_orphan" "${#content_orphan}" |
| 828 | |
| 829 | # test config option |
| 830 | git config lfs.pruneverifyunreachablealways true |
| 831 | git lfs prune --verify-remote 2>&1 | tee prune.log |
| 832 | grep "5 local objects, 1 retained, 3 verified with remote, 1 not on remote, done." prune.log |
| 833 | grep "missing on remote:" prune.log |
| 834 | grep "$oid_orphan" prune.log |
| 835 | |
| 836 | # now try overriding the global option |
| 837 | git lfs prune --verify-remote --no-verify-unreachable --dry-run 2>&1 | tee prune.log |
| 838 | grep "5 local objects, 1 retained, 3 verified with remote, done." prune.log |
| 839 | grep "4 files would be pruned" prune.log |
| 840 | |
| 841 | # now test with continue to see that it does prune verified objects |
| 842 | git lfs prune --verify-remote --when-unverified=continue 2>&1 | tee prune.log |
| 843 | grep "5 local objects, 1 retained, 3 verified with remote, 1 not on remote, done." prune.log |
| 844 | grep "Deleting objects: 100% (3/3), done." prune.log |
| 845 | |
| 846 | # The orphan file should not have been deleted |
| 847 | refute_local_object "$oid_commit1" "${#content_commit1}" |
| 848 | refute_local_object "$oid_commit2" "${#content_commit2}" |
| 849 | refute_local_object "$oid_commit3" "${#content_commit3}" |
| 850 | assert_local_object "$oid_orphan" "${#content_orphan}" |
| 851 | ) |
| 852 | end_test |
| 853 | |
| 854 | begin_test "prune keep stashed changes" |
| 855 | ( |
| 856 | set -e |
| 857 | |
| 858 | reponame="prune_keep_stashed" |
| 859 | setup_remote_repo "remote_$reponame" |
| 860 | |
| 861 | clone_repo "remote_$reponame" "clone_$reponame" |
| 862 | |
| 863 | git lfs track "*.dat" 2>&1 | tee track.log |
| 864 | grep "Tracking \"\*.dat\"" track.log |
| 865 | |
| 866 | # generate content we'll use |
| 867 | content_oldandpushed="To delete: pushed and too old" |
| 868 | oid_oldandpushed=$(calc_oid "$content_oldandpushed") |
| 869 | content_unreferenced="To delete: unreferenced" |
| 870 | oid_unreferenced=$(calc_oid "$content_unreferenced") |
| 871 | content_retain1="Retained content 1" |
| 872 | oid_retain1=$(calc_oid "$content_retain1") |
| 873 | |
| 874 | content_inrepo="This is the original committed data" |
| 875 | oid_inrepo=$(calc_oid "$content_inrepo") |
| 876 | content_stashed="This data will be stashed and should not be deleted" |
| 877 | oid_stashed=$(calc_oid "$content_stashed") |
| 878 | content_stashedandexcluded="This data will be stashed and should not be deleted despite being excluded" |
| 879 | oid_stashedandexcluded=$(calc_oid "$content_stashedandexcluded") |
| 880 | content_stashedbranch="This data will be stashed on a branch and should not be deleted" |
| 881 | oid_stashedbranch=$(calc_oid "$content_stashedbranch") |
| 882 | content_stashedandexcludedbranch="This data will be stashed on a branch and should not be deleted despite being excluded" |
| 883 | oid_stashedandexcludedbranch=$(calc_oid "$content_stashedandexcludedbranch") |
| 884 | |
| 885 | # We need to test with older commits to ensure they get pruned as expected |
| 886 | echo "[ |
| 887 | { |
| 888 | \"CommitDate\":\"$(get_date -20d)\", |
| 889 | \"Files\":[ |
| 890 | {\"Filename\":\"old.dat\",\"Size\":${#content_oldandpushed}, \"Data\":\"$content_oldandpushed\"}] |
| 891 | }, |
| 892 | { |
| 893 | \"CommitDate\":\"$(get_date -7d)\", |
| 894 | \"Files\":[ |
| 895 | {\"Filename\":\"old.dat\",\"Size\":${#content_retain1}, \"Data\":\"$content_retain1\"}] |
| 896 | }, |
| 897 | { |
| 898 | \"CommitDate\":\"$(get_date -4d)\", |
| 899 | \"NewBranch\":\"branch_to_delete\", |
| 900 | \"Files\":[ |
| 901 | {\"Filename\":\"unreferenced.dat\",\"Size\":${#content_unreferenced}, \"Data\":\"$content_unreferenced\"}, |
| 902 | {\"Filename\":\"foo/unreferenced.dat\",\"Size\":${#content_unreferenced}, \"Data\":\"$content_unreferenced\"}] |
| 903 | }, |
| 904 | { |
| 905 | \"CommitDate\":\"$(get_date -1d)\", |
| 906 | \"ParentBranches\":[\"main\"], |
| 907 | \"Files\":[ |
| 908 | {\"Filename\":\"stashedfile.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}, |
| 909 | {\"Filename\":\"foo/stashedfile.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}] |
| 910 | } |
| 911 | ]" | lfstest-testutils addcommits |
| 912 | |
| 913 | git push origin main |
| 914 | |
| 915 | assert_local_object "$oid_oldandpushed" "${#content_oldandpushed}" |
| 916 | assert_local_object "$oid_unreferenced" "${#content_unreferenced}" |
| 917 | assert_local_object "$oid_retain1" "${#content_retain1}" |
| 918 | |
| 919 | # now modify the files, and stash them |
| 920 | printf '%s' "$content_stashed" > stashedfile.dat |
| 921 | printf '%s' "$content_stashedandexcluded" > foo/stashedfile.dat |
| 922 | git stash |
| 923 | |
| 924 | # Switch to a branch, modify files, stash them, and delete the branch. |
| 925 | git checkout branch_to_delete |
| 926 | printf '%s' "$content_stashedbranch" > unreferenced.dat |
| 927 | printf '%s' "$content_stashedandexcludedbranch" > foo/unreferenced.dat |
| 928 | git stash |
| 929 | git checkout main |
| 930 | git branch -D branch_to_delete |
| 931 | |
| 932 | # Prove that the stashed data was stored in LFS (should call clean filter) |
| 933 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 934 | assert_local_object "$oid_stashedandexcluded" "${#content_stashedandexcluded}" |
| 935 | assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}" |
| 936 | assert_local_object "$oid_stashedandexcludedbranch" "${#content_stashedandexcludedbranch}" |
| 937 | |
| 938 | # We need to prevent MSYS from rewriting /foo into a Windows path. |
| 939 | MSYS_NO_PATHCONV=1 git config "lfs.fetchexclude" "/foo" |
| 940 | |
| 941 | # force color codes in git diff meta-information |
| 942 | git config color.diff always |
| 943 | |
| 944 | # Prune data, should NOT delete stashed files |
| 945 | git lfs prune |
| 946 | |
| 947 | refute_local_object "$oid_oldandpushed" "${#content_oldandpushed}" |
| 948 | refute_local_object "$oid_unreferenced" "${#content_unreferenced}" |
| 949 | assert_local_object "$oid_retain1" "${#content_retain1}" |
| 950 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 951 | assert_local_object "$oid_stashedandexcluded" "${#content_stashedandexcluded}" |
| 952 | assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}" |
| 953 | assert_local_object "$oid_stashedandexcludedbranch" "${#content_stashedandexcludedbranch}" |
| 954 | ) |
| 955 | end_test |
| 956 | |
| 957 | begin_test "prune keep stashed changes in index" |
| 958 | ( |
| 959 | set -e |
| 960 | |
| 961 | reponame="prune_keep_stashed_index" |
| 962 | setup_remote_repo "remote_$reponame" |
| 963 | |
| 964 | clone_repo "remote_$reponame" "clone_$reponame" |
| 965 | |
| 966 | git lfs track "*.dat" 2>&1 | tee track.log |
| 967 | grep "Tracking \"\*.dat\"" track.log |
| 968 | |
| 969 | # generate content we'll use |
| 970 | content_oldandpushed="To delete: pushed and too old" |
| 971 | oid_oldandpushed=$(calc_oid "$content_oldandpushed") |
| 972 | content_unreferenced="To delete: unreferenced" |
| 973 | oid_unreferenced=$(calc_oid "$content_unreferenced") |
| 974 | content_retain1="Retained content 1" |
| 975 | oid_retain1=$(calc_oid "$content_retain1") |
| 976 | |
| 977 | content_inrepo="This is the original committed data" |
| 978 | oid_inrepo=$(calc_oid "$content_inrepo") |
| 979 | content_indexstashed="This data will be stashed from the index and should not be deleted" |
| 980 | oid_indexstashed=$(calc_oid "$content_indexstashed") |
| 981 | content_indexstashedandexcluded="This data will be stashed from the index and should not be deleted despite being excluded" |
| 982 | oid_indexstashedandexcluded=$(calc_oid "$content_indexstashedandexcluded") |
| 983 | content_stashed="This data will be stashed and should not be deleted" |
| 984 | oid_stashed=$(calc_oid "$content_stashed") |
| 985 | content_stashedandexcluded="This data will be stashed and should not be deleted despite being excluded" |
| 986 | oid_stashedandexcluded=$(calc_oid "$content_stashedandexcluded") |
| 987 | content_indexstashedbranch="This data will be stashed on a branch from the index and should not be deleted" |
| 988 | oid_indexstashedbranch=$(calc_oid "$content_indexstashedbranch") |
| 989 | content_indexstashedandexcludedbranch="This data will be stashed on a branch from the index and should not be deleted despite being excluded" |
| 990 | oid_indexstashedandexcludedbranch=$(calc_oid "$content_indexstashedandexcludedbranch") |
| 991 | content_stashedbranch="This data will be stashed on a branch and should not be deleted" |
| 992 | oid_stashedbranch=$(calc_oid "$content_stashedbranch") |
| 993 | content_stashedandexcludedbranch="This data will be stashed on a branch and should not be deleted despite being excluded" |
| 994 | oid_stashedandexcludedbranch=$(calc_oid "$content_stashedandexcludedbranch") |
| 995 | |
| 996 | # We need to test with older commits to ensure they get pruned as expected |
| 997 | echo "[ |
| 998 | { |
| 999 | \"CommitDate\":\"$(get_date -20d)\", |
| 1000 | \"Files\":[ |
| 1001 | {\"Filename\":\"old.dat\",\"Size\":${#content_oldandpushed}, \"Data\":\"$content_oldandpushed\"}] |
| 1002 | }, |
| 1003 | { |
| 1004 | \"CommitDate\":\"$(get_date -7d)\", |
| 1005 | \"Files\":[ |
| 1006 | {\"Filename\":\"old.dat\",\"Size\":${#content_retain1}, \"Data\":\"$content_retain1\"}] |
| 1007 | }, |
| 1008 | { |
| 1009 | \"CommitDate\":\"$(get_date -4d)\", |
| 1010 | \"NewBranch\":\"branch_to_delete\", |
| 1011 | \"Files\":[ |
| 1012 | {\"Filename\":\"unreferenced.dat\",\"Size\":${#content_unreferenced}, \"Data\":\"$content_unreferenced\"}, |
| 1013 | {\"Filename\":\"foo/unreferenced.dat\",\"Size\":${#content_unreferenced}, \"Data\":\"$content_unreferenced\"}] |
| 1014 | }, |
| 1015 | { |
| 1016 | \"CommitDate\":\"$(get_date -1d)\", |
| 1017 | \"ParentBranches\":[\"main\"], |
| 1018 | \"Files\":[ |
| 1019 | {\"Filename\":\"stashedfile.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}, |
| 1020 | {\"Filename\":\"foo/stashedfile.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}] |
| 1021 | } |
| 1022 | ]" | lfstest-testutils addcommits |
| 1023 | |
| 1024 | git push origin main |
| 1025 | |
| 1026 | assert_local_object "$oid_oldandpushed" "${#content_oldandpushed}" |
| 1027 | assert_local_object "$oid_unreferenced" "${#content_unreferenced}" |
| 1028 | assert_local_object "$oid_retain1" "${#content_retain1}" |
| 1029 | |
| 1030 | # now modify the files, and add them to the index |
| 1031 | printf '%s' "$content_indexstashed" > stashedfile.dat |
| 1032 | printf '%s' "$content_indexstashedandexcluded" > foo/stashedfile.dat |
| 1033 | git add stashedfile.dat foo/stashedfile.dat |
| 1034 | |
| 1035 | # now modify the files again, and stash them |
| 1036 | printf '%s' "$content_stashed" > stashedfile.dat |
| 1037 | printf '%s' "$content_stashedandexcluded" > foo/stashedfile.dat |
| 1038 | git stash |
| 1039 | |
| 1040 | # Switch to a branch, modify files in the index and working tree, stash them, |
| 1041 | # and delete the branch. |
| 1042 | git checkout branch_to_delete |
| 1043 | printf '%s' "$content_indexstashedbranch" > unreferenced.dat |
| 1044 | printf '%s' "$content_indexstashedandexcludedbranch" > foo/unreferenced.dat |
| 1045 | git add unreferenced.dat foo/unreferenced.dat |
| 1046 | printf '%s' "$content_stashedbranch" > unreferenced.dat |
| 1047 | printf '%s' "$content_stashedandexcludedbranch" > foo/unreferenced.dat |
| 1048 | git stash |
| 1049 | git checkout main |
| 1050 | git branch -D branch_to_delete |
| 1051 | |
| 1052 | # Prove that the stashed data was stored in LFS (should call clean filter) |
| 1053 | assert_local_object "$oid_indexstashed" "${#content_indexstashed}" |
| 1054 | assert_local_object "$oid_indexstashedandexcluded" "${#content_indexstashedandexcluded}" |
| 1055 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1056 | assert_local_object "$oid_stashedandexcluded" "${#content_stashedandexcluded}" |
| 1057 | assert_local_object "$oid_indexstashedbranch" "${#content_indexstashedbranch}" |
| 1058 | assert_local_object "$oid_indexstashedandexcludedbranch" "${#content_indexstashedandexcludedbranch}" |
| 1059 | assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}" |
| 1060 | assert_local_object "$oid_stashedandexcludedbranch" "${#content_stashedandexcludedbranch}" |
| 1061 | |
| 1062 | # We need to prevent MSYS from rewriting /foo into a Windows path. |
| 1063 | MSYS_NO_PATHCONV=1 git config "lfs.fetchexclude" "/foo" |
| 1064 | |
| 1065 | # force color codes in git diff meta-information |
| 1066 | git config color.diff always |
| 1067 | |
| 1068 | # Prune data, should NOT delete stashed file or stashed changes to index |
| 1069 | git lfs prune |
| 1070 | |
| 1071 | refute_local_object "$oid_oldandpushed" "${#content_oldandpushed}" |
| 1072 | refute_local_object "$oid_unreferenced" "${#content_unreferenced}" |
| 1073 | assert_local_object "$oid_retain1" "${#content_retain1}" |
| 1074 | assert_local_object "$oid_indexstashed" "${#content_indexstashed}" |
| 1075 | assert_local_object "$oid_indexstashedandexcluded" "${#content_indexstashedandexcluded}" |
| 1076 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1077 | assert_local_object "$oid_stashedandexcluded" "${#content_stashedandexcluded}" |
| 1078 | assert_local_object "$oid_indexstashedbranch" "${#content_indexstashedbranch}" |
| 1079 | assert_local_object "$oid_indexstashedandexcludedbranch" "${#content_indexstashedandexcludedbranch}" |
| 1080 | assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}" |
| 1081 | assert_local_object "$oid_stashedandexcludedbranch" "${#content_stashedandexcludedbranch}" |
| 1082 | ) |
| 1083 | end_test |
| 1084 | |
| 1085 | begin_test "prune keep stashed untracked files" |
| 1086 | ( |
| 1087 | set -e |
| 1088 | |
| 1089 | reponame="prune_keep_stashed_untracked" |
| 1090 | setup_remote_repo "remote_$reponame" |
| 1091 | |
| 1092 | clone_repo "remote_$reponame" "clone_$reponame" |
| 1093 | |
| 1094 | git lfs track "*.dat" 2>&1 | tee track.log |
| 1095 | grep "Tracking \"\*.dat\"" track.log |
| 1096 | |
| 1097 | # Commit .gitattributes first so it is not removed by "git stash -u" and then |
| 1098 | # not restored when we checkout the branch and try to modify LFS objects. |
| 1099 | git add .gitattributes |
| 1100 | git commit -m attribs |
| 1101 | |
| 1102 | # generate content we'll use |
| 1103 | content_oldandpushed="To delete: pushed and too old" |
| 1104 | oid_oldandpushed=$(calc_oid "$content_oldandpushed") |
| 1105 | content_unreferenced="To delete: unreferenced" |
| 1106 | oid_unreferenced=$(calc_oid "$content_unreferenced") |
| 1107 | content_retain1="Retained content 1" |
| 1108 | oid_retain1=$(calc_oid "$content_retain1") |
| 1109 | |
| 1110 | content_inrepo="This is the original committed data" |
| 1111 | oid_inrepo=$(calc_oid "$content_inrepo") |
| 1112 | content_indexstashed="This data will be stashed from the index and should not be deleted" |
| 1113 | oid_indexstashed=$(calc_oid "$content_indexstashed") |
| 1114 | content_indexstashedandexcluded="This data will be stashed from the index and should not be deleted despite being excluded" |
| 1115 | oid_indexstashedandexcluded=$(calc_oid "$content_indexstashedandexcluded") |
| 1116 | content_stashed="This data will be stashed and should not be deleted" |
| 1117 | oid_stashed=$(calc_oid "$content_stashed") |
| 1118 | content_stashedandexcluded="This data will be stashed and should not be deleted despite being excluded" |
| 1119 | oid_stashedandexcluded=$(calc_oid "$content_stashedandexcluded") |
| 1120 | content_untrackedstashed="This UNTRACKED FILE data will be stashed and should not be deleted" |
| 1121 | oid_untrackedstashed=$(calc_oid "$content_untrackedstashed") |
| 1122 | content_untrackedstashedandexcluded="This UNTRACKED FILE data will be stashed and should not be deleted despite being excluded" |
| 1123 | oid_untrackedstashedandexcluded=$(calc_oid "$content_untrackedstashedandexcluded") |
| 1124 | content_indexstashedbranch="This data will be stashed on a branch from the index and should not be deleted" |
| 1125 | oid_indexstashedbranch=$(calc_oid "$content_indexstashedbranch") |
| 1126 | content_indexstashedandexcludedbranch="This data will be stashed on a branch from the index and should not be deleted despite being excluded" |
| 1127 | oid_indexstashedandexcludedbranch=$(calc_oid "$content_indexstashedandexcludedbranch") |
| 1128 | content_stashedbranch="This data will be stashed on a branch and should not be deleted" |
| 1129 | oid_stashedbranch=$(calc_oid "$content_stashedbranch") |
| 1130 | content_stashedandexcludedbranch="This data will be stashed on a branch and should not be deleted despite being excluded" |
| 1131 | oid_stashedandexcludedbranch=$(calc_oid "$content_stashedandexcludedbranch") |
| 1132 | content_untrackedstashedbranch="This UNTRACKED FILE data will be stashed on a branch and should not be deleted" |
| 1133 | oid_untrackedstashedbranch=$(calc_oid "$content_untrackedstashedbranch") |
| 1134 | content_untrackedstashedandexcludedbranch="This UNTRACKED FILE data will be stashed on a branch and should not be deleted despite being excluded" |
| 1135 | oid_untrackedstashedandexcludedbranch=$(calc_oid "$content_untrackedstashedandexcludedbranch") |
| 1136 | |
| 1137 | # We need to test with older commits to ensure they get pruned as expected |
| 1138 | echo "[ |
| 1139 | { |
| 1140 | \"CommitDate\":\"$(get_date -20d)\", |
| 1141 | \"Files\":[ |
| 1142 | {\"Filename\":\"old.dat\",\"Size\":${#content_oldandpushed}, \"Data\":\"$content_oldandpushed\"}] |
| 1143 | }, |
| 1144 | { |
| 1145 | \"CommitDate\":\"$(get_date -7d)\", |
| 1146 | \"Files\":[ |
| 1147 | {\"Filename\":\"old.dat\",\"Size\":${#content_retain1}, \"Data\":\"$content_retain1\"}] |
| 1148 | }, |
| 1149 | { |
| 1150 | \"CommitDate\":\"$(get_date -4d)\", |
| 1151 | \"NewBranch\":\"branch_to_delete\", |
| 1152 | \"Files\":[ |
| 1153 | {\"Filename\":\"unreferenced.dat\",\"Size\":${#content_unreferenced}, \"Data\":\"$content_unreferenced\"}, |
| 1154 | {\"Filename\":\"foo/unreferenced.dat\",\"Size\":${#content_unreferenced}, \"Data\":\"$content_unreferenced\"}] |
| 1155 | }, |
| 1156 | { |
| 1157 | \"CommitDate\":\"$(get_date -1d)\", |
| 1158 | \"ParentBranches\":[\"main\"], |
| 1159 | \"Files\":[ |
| 1160 | {\"Filename\":\"stashedfile.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}, |
| 1161 | {\"Filename\":\"foo/stashedfile.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}] |
| 1162 | } |
| 1163 | ]" | lfstest-testutils addcommits |
| 1164 | |
| 1165 | git push origin main |
| 1166 | |
| 1167 | assert_local_object "$oid_oldandpushed" "${#content_oldandpushed}" |
| 1168 | assert_local_object "$oid_unreferenced" "${#content_unreferenced}" |
| 1169 | assert_local_object "$oid_retain1" "${#content_retain1}" |
| 1170 | |
| 1171 | # now modify the files, and add them to the index |
| 1172 | printf '%s' "$content_indexstashed" > stashedfile.dat |
| 1173 | printf '%s' "$content_indexstashedandexcluded" > foo/stashedfile.dat |
| 1174 | git add stashedfile.dat foo/stashedfile.dat |
| 1175 | |
| 1176 | # now modify the files again, and stash them |
| 1177 | printf '%s' "$content_stashed" > stashedfile.dat |
| 1178 | printf '%s' "$content_stashedandexcluded" > foo/stashedfile.dat |
| 1179 | |
| 1180 | # Also create untracked files |
| 1181 | printf '%s' "$content_untrackedstashed" > untrackedfile.dat |
| 1182 | printf '%s' "$content_untrackedstashedandexcluded" > foo/untrackedfile.dat |
| 1183 | |
| 1184 | # stash, including untracked |
| 1185 | git stash -u |
| 1186 | |
| 1187 | # Switch to a branch, modify files in the index and working tree and create |
| 1188 | # untracked files, stash them, and delete the branch. |
| 1189 | git checkout branch_to_delete |
| 1190 | printf '%s' "$content_indexstashedbranch" > unreferenced.dat |
| 1191 | printf '%s' "$content_indexstashedandexcludedbranch" > foo/unreferenced.dat |
| 1192 | git add unreferenced.dat foo/unreferenced.dat |
| 1193 | printf '%s' "$content_stashedbranch" > unreferenced.dat |
| 1194 | printf '%s' "$content_stashedandexcludedbranch" > foo/unreferenced.dat |
| 1195 | printf '%s' "$content_untrackedstashedbranch" > untrackedfile.dat |
| 1196 | printf '%s' "$content_untrackedstashedandexcludedbranch" > foo/untrackedfile.dat |
| 1197 | git stash -u |
| 1198 | git checkout main |
| 1199 | git branch -D branch_to_delete |
| 1200 | |
| 1201 | # Prove that ALL stashed data was stored in LFS (should call clean filter) |
| 1202 | assert_local_object "$oid_indexstashed" "${#content_indexstashed}" |
| 1203 | assert_local_object "$oid_indexstashedandexcluded" "${#content_indexstashedandexcluded}" |
| 1204 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1205 | assert_local_object "$oid_stashedandexcluded" "${#content_stashedandexcluded}" |
| 1206 | assert_local_object "$oid_untrackedstashed" "${#content_untrackedstashed}" |
| 1207 | assert_local_object "$oid_untrackedstashedandexcluded" "${#content_untrackedstashedandexcluded}" |
| 1208 | assert_local_object "$oid_indexstashedbranch" "${#content_indexstashedbranch}" |
| 1209 | assert_local_object "$oid_indexstashedandexcludedbranch" "${#content_indexstashedandexcludedbranch}" |
| 1210 | assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}" |
| 1211 | assert_local_object "$oid_stashedandexcludedbranch" "${#content_stashedandexcludedbranch}" |
| 1212 | assert_local_object "$oid_untrackedstashedbranch" "${#content_untrackedstashedbranch}" |
| 1213 | assert_local_object "$oid_untrackedstashedandexcludedbranch" "${#content_untrackedstashedandexcludedbranch}" |
| 1214 | |
| 1215 | # We need to prevent MSYS from rewriting /foo into a Windows path. |
| 1216 | MSYS_NO_PATHCONV=1 git config "lfs.fetchexclude" "/foo" |
| 1217 | |
| 1218 | # force color codes in git diff meta-information |
| 1219 | git config color.diff always |
| 1220 | |
| 1221 | # Prune data, should NOT delete stashed file or stashed changes to index |
| 1222 | git lfs prune |
| 1223 | |
| 1224 | refute_local_object "$oid_oldandpushed" "${#content_oldandpushed}" |
| 1225 | refute_local_object "$oid_unreferenced" "${#content_unreferenced}" |
| 1226 | assert_local_object "$oid_retain1" "${#content_retain1}" |
| 1227 | assert_local_object "$oid_indexstashed" "${#content_indexstashed}" |
| 1228 | assert_local_object "$oid_indexstashedandexcluded" "${#content_indexstashedandexcluded}" |
| 1229 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1230 | assert_local_object "$oid_stashedandexcluded" "${#content_stashedandexcluded}" |
| 1231 | assert_local_object "$oid_untrackedstashed" "${#content_untrackedstashed}" |
| 1232 | assert_local_object "$oid_untrackedstashedandexcluded" "${#content_untrackedstashedandexcluded}" |
| 1233 | assert_local_object "$oid_indexstashedbranch" "${#content_indexstashedbranch}" |
| 1234 | assert_local_object "$oid_indexstashedandexcludedbranch" "${#content_indexstashedandexcludedbranch}" |
| 1235 | assert_local_object "$oid_stashedbranch" "${#content_stashedbranch}" |
| 1236 | assert_local_object "$oid_stashedandexcludedbranch" "${#content_stashedandexcludedbranch}" |
| 1237 | assert_local_object "$oid_untrackedstashedbranch" "${#content_untrackedstashedbranch}" |
| 1238 | assert_local_object "$oid_untrackedstashedandexcludedbranch" "${#content_untrackedstashedandexcludedbranch}" |
| 1239 | ) |
| 1240 | end_test |
| 1241 | |
| 1242 | begin_test "prune recent changes with --recent" |
| 1243 | ( |
| 1244 | set -e |
| 1245 | |
| 1246 | reponame="prune_recent_arg" |
| 1247 | setup_remote_repo "remote_$reponame" |
| 1248 | |
| 1249 | clone_repo "remote_$reponame" "clone_$reponame" |
| 1250 | |
| 1251 | git lfs track "*.dat" |
| 1252 | |
| 1253 | # generate content we'll use |
| 1254 | content_inrepo="this is the original committed data" |
| 1255 | oid_inrepo=$(calc_oid "$content_inrepo") |
| 1256 | content_new="this data will be recent" |
| 1257 | oid_new=$(calc_oid "$content_new") |
| 1258 | content_stashed="This data will be stashed and should not be deleted" |
| 1259 | oid_stashed=$(calc_oid "$content_stashed") |
| 1260 | |
| 1261 | echo "[ |
| 1262 | { |
| 1263 | \"CommitDate\":\"$(get_date -1d)\", |
| 1264 | \"Files\":[ |
| 1265 | {\"Filename\":\"file.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}] |
| 1266 | } |
| 1267 | ]" | lfstest-testutils addcommits |
| 1268 | |
| 1269 | # now modify the file, and commit it |
| 1270 | printf '%s' "$content_new" > file.dat |
| 1271 | git add . |
| 1272 | git commit -m 'Update file.dat' |
| 1273 | |
| 1274 | # now modify the file, and stash it |
| 1275 | printf '%s' "$content_stashed" > file.dat |
| 1276 | git stash |
| 1277 | |
| 1278 | git config lfs.fetchrecentrefsdays 5 |
| 1279 | git config lfs.fetchrecentremoterefs true |
| 1280 | git config lfs.fetchrecentcommitsdays 3 |
| 1281 | |
| 1282 | assert_local_object "$oid_new" "${#content_new}" |
| 1283 | assert_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1284 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1285 | |
| 1286 | # prune data, should not delete. |
| 1287 | git lfs prune --recent |
| 1288 | |
| 1289 | assert_local_object "$oid_new" "${#content_new}" |
| 1290 | assert_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1291 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1292 | |
| 1293 | git push origin HEAD |
| 1294 | |
| 1295 | # prune data. |
| 1296 | git lfs prune --recent |
| 1297 | |
| 1298 | assert_local_object "$oid_new" "${#content_new}" |
| 1299 | refute_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1300 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1301 | ) |
| 1302 | end_test |
| 1303 | |
| 1304 | begin_test "prune keep files in index" |
| 1305 | ( |
| 1306 | set -e |
| 1307 | |
| 1308 | reponame="prune_index" |
| 1309 | setup_remote_repo "remote_$reponame" |
| 1310 | |
| 1311 | clone_repo "remote_$reponame" "clone_$reponame" |
| 1312 | |
| 1313 | git lfs track "*.dat" |
| 1314 | |
| 1315 | # generate content we'll use |
| 1316 | content_inrepo="this is the original committed data" |
| 1317 | oid_inrepo=$(calc_oid "$content_inrepo") |
| 1318 | content_new="this data will be indexed" |
| 1319 | oid_new=$(calc_oid "$content_new") |
| 1320 | content_untracked="This data will be untracked and added to the index and should not be deleted" |
| 1321 | oid_untracked=$(calc_oid "$content_untracked") |
| 1322 | |
| 1323 | echo "[ |
| 1324 | { |
| 1325 | \"CommitDate\":\"$(get_date -1d)\", |
| 1326 | \"Files\":[ |
| 1327 | {\"Filename\":\"file.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}] |
| 1328 | } |
| 1329 | ]" | lfstest-testutils addcommits |
| 1330 | |
| 1331 | # now modify the file, and add it to the index |
| 1332 | printf '%s' "$content_new" > file.dat |
| 1333 | git add . |
| 1334 | |
| 1335 | # now add the file, and add it to the index |
| 1336 | printf '%s' "$content_untracked" > untracked.dat |
| 1337 | git add . |
| 1338 | |
| 1339 | assert_local_object "$oid_new" "${#content_new}" |
| 1340 | assert_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1341 | assert_local_object "$oid_untracked" "${#content_untracked}" |
| 1342 | |
| 1343 | # prune data, should not delete. |
| 1344 | git lfs prune |
| 1345 | |
| 1346 | assert_local_object "$oid_new" "${#content_new}" |
| 1347 | assert_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1348 | assert_local_object "$oid_untracked" "${#content_untracked}" |
| 1349 | |
| 1350 | git push origin HEAD |
| 1351 | |
| 1352 | # force prune data should not delete in index |
| 1353 | git lfs prune --force |
| 1354 | |
| 1355 | assert_local_object "$oid_new" "${#content_new}" |
| 1356 | refute_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1357 | assert_local_object "$oid_untracked" "${#content_untracked}" |
| 1358 | ) |
| 1359 | end_test |
| 1360 | |
| 1361 | begin_test "prune --force" |
| 1362 | ( |
| 1363 | set -e |
| 1364 | |
| 1365 | reponame="prune_force" |
| 1366 | setup_remote_repo "remote_$reponame" |
| 1367 | |
| 1368 | clone_repo "remote_$reponame" "clone_$reponame" |
| 1369 | |
| 1370 | git lfs track "*.dat" |
| 1371 | |
| 1372 | # generate content we'll use |
| 1373 | content_inrepo="this is the original committed data" |
| 1374 | oid_inrepo=$(calc_oid "$content_inrepo") |
| 1375 | content_new="this data will be recent" |
| 1376 | oid_new=$(calc_oid "$content_new") |
| 1377 | content_stashed="This data will be stashed and should not be deleted" |
| 1378 | oid_stashed=$(calc_oid "$content_stashed") |
| 1379 | |
| 1380 | echo "[ |
| 1381 | { |
| 1382 | \"CommitDate\":\"$(get_date -1d)\", |
| 1383 | \"Files\":[ |
| 1384 | {\"Filename\":\"file.dat\",\"Size\":${#content_inrepo}, \"Data\":\"$content_inrepo\"}] |
| 1385 | } |
| 1386 | ]" | lfstest-testutils addcommits |
| 1387 | |
| 1388 | # now modify the file, and commit it |
| 1389 | printf '%s' "$content_new" > file.dat |
| 1390 | git add . |
| 1391 | git commit -m 'Update file.dat' |
| 1392 | |
| 1393 | # now modify the file, and stash it |
| 1394 | printf '%s' "$content_stashed" > file.dat |
| 1395 | git stash |
| 1396 | |
| 1397 | git config lfs.fetchrecentrefsdays 5 |
| 1398 | git config lfs.fetchrecentremoterefs true |
| 1399 | git config lfs.fetchrecentcommitsdays 3 |
| 1400 | |
| 1401 | assert_local_object "$oid_new" "${#content_new}" |
| 1402 | assert_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1403 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1404 | |
| 1405 | # prune data, should not delete. |
| 1406 | git lfs prune --force |
| 1407 | |
| 1408 | assert_local_object "$oid_new" "${#content_new}" |
| 1409 | assert_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1410 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1411 | |
| 1412 | git push origin HEAD |
| 1413 | |
| 1414 | # prune data. |
| 1415 | git lfs prune --force |
| 1416 | |
| 1417 | refute_local_object "$oid_new" "${#content_new}" |
| 1418 | refute_local_object "$oid_inrepo" "${#content_inrepo}" |
| 1419 | assert_local_object "$oid_stashed" "${#content_stashed}" |
| 1420 | ) |
| 1421 | end_test |
| 1422 | |
| 1423 | begin_test "prune does not fail on empty files" |
| 1424 | ( |
| 1425 | set -e |
| 1426 | |
| 1427 | reponame="prune-empty-file" |
| 1428 | setup_remote_repo "remote-$reponame" |
| 1429 | |
| 1430 | clone_repo "remote-$reponame" "clone-$reponame" |
| 1431 | |
| 1432 | git lfs track "*.dat" 2>&1 | tee track.log |
| 1433 | grep "Tracking \"\*.dat\"" track.log |
| 1434 | |
| 1435 | touch empty.dat |
| 1436 | git add .gitattributes empty.dat |
| 1437 | git commit -m 'Add empty' |
| 1438 | git push origin main |
| 1439 | |
| 1440 | git lfs prune --force |
| 1441 | ) |
| 1442 | end_test |
| 1443 | |
| 1444 | begin_test "prune does not invoke external diff programs" |
| 1445 | ( |
| 1446 | set -e |
| 1447 | |
| 1448 | reponame="prune-external-diff" |
| 1449 | setup_remote_repo "remote-$reponame" |
| 1450 | |
| 1451 | clone_repo "remote-$reponame" "clone-$reponame" |
| 1452 | |
| 1453 | git config diff.word.textconv 'false' |
| 1454 | echo "*.dot diff=word" >.git/info/attributes |
| 1455 | |
| 1456 | for n in $(seq 1000); do (echo "$n" > "$n.dot") done |
| 1457 | git add . |
| 1458 | git commit -am "initial" |
| 1459 | git lfs prune |
| 1460 | ) |
| 1461 | end_test |
| 1462 | |
| 1463 | begin_test "prune doesn't hang on long lines in diff" |
| 1464 | ( |
| 1465 | set -e |
| 1466 | |
| 1467 | reponame="prune_longlines" |
| 1468 | git init "$reponame" |
| 1469 | cd "$reponame" |
| 1470 | |
| 1471 | git lfs track "*.dat" 2>&1 | tee track.log |
| 1472 | grep "Tracking \"\*.dat\"" track.log |
| 1473 | |
| 1474 | echo "test data" >test.dat |
| 1475 | git add .gitattributes test.dat |
| 1476 | |
| 1477 | git commit -m tracked |
| 1478 | |
| 1479 | git lfs untrack "*.dat" 2>&1 | tee untrack.log |
| 1480 | grep "Untracking \"\*.dat\"" untrack.log |
| 1481 | |
| 1482 | # Test with a file size significantly larger than the maximum size |
| 1483 | # of the token buffer used by the bufio.Scanner interface. |
| 1484 | # See https://github.com/git-lfs/git-lfs/pull/4557. |
| 1485 | max_bufio_scan_token_size="$(lfstest-getlimit --max-bufio-scan-token-size)" |
| 1486 | head -c $((max_bufio_scan_token_size * 2)) /dev/zero | tr '\0' 'A' >test.dat |
| 1487 | |
| 1488 | git add .gitattributes test.dat |
| 1489 | |
| 1490 | git commit -m untracked |
| 1491 | |
| 1492 | git lfs prune |
| 1493 | ) |
| 1494 | end_test |
| 1495 | |
| 1496 | begin_test "prune doesn't hang on long lines in stash diff" |
| 1497 | ( |
| 1498 | set -e |
| 1499 | |
| 1500 | reponame="prune_longlines" |
| 1501 | git init "$reponame" |
| 1502 | cd "$reponame" |
| 1503 | |
| 1504 | git lfs track "*.dat" 2>&1 | tee track.log |
| 1505 | grep "Tracking \"\*.dat\"" track.log |
| 1506 | |
| 1507 | echo "test data" >test.dat |
| 1508 | git add .gitattributes test.dat |
| 1509 | |
| 1510 | git commit -m tracked |
| 1511 | |
| 1512 | git lfs untrack "*.dat" 2>&1 | tee untrack.log |
| 1513 | grep "Untracking \"\*.dat\"" untrack.log |
| 1514 | |
| 1515 | # Test with a file size significantly larger than the maximum size |
| 1516 | # of the token buffer used by the bufio.Scanner interface. |
| 1517 | # See https://github.com/git-lfs/git-lfs/pull/4557. |
| 1518 | max_bufio_scan_token_size="$(lfstest-getlimit --max-bufio-scan-token-size)" |
| 1519 | head -c $((max_bufio_scan_token_size * 2)) /dev/zero | tr '\0' 'A' >test.dat |
| 1520 | |
| 1521 | git stash |
| 1522 | |
| 1523 | git lfs prune |
| 1524 | ) |
| 1525 | end_test |