5 ensure_git_version_isnt $VERSION_LOWER "2.5.0"
7 begin_test "prune worktree"
12 reponame="prune_worktree"
13 setup_remote_repo "remote_$reponame"
15 clone_repo "remote_$reponame" "$reponame"
17 git lfs track "*.dat" 2>&1 | tee track.log
18 grep "Tracking \"\*.dat\"" track.log
20 content_head="First checkout HEAD"
21 content_worktree1head="Worktree 1 head"
22 content_worktree2head="Worktree 2 head"
23 content_oldcommit1="Always pruned 1"
24 content_oldcommit2="Always pruned 2"
25 content_oldcommit3="Always pruned 3"
27 oid_head=$(calc_oid "$content_head")
28 oid_worktree1head=$(calc_oid "$content_worktree1head")
29 oid_worktree2head=$(calc_oid "$content_worktree2head")
30 oid_oldcommit1=$(calc_oid "$content_oldcommit1")
31 oid_oldcommit2=$(calc_oid "$content_oldcommit2")
32 oid_oldcommit3=$(calc_oid "$content_oldcommit3")
36 \"CommitDate\":\"$(get_date -40d)\",
38 {\"Filename\":\"file.dat\",\"Size\":${#content_oldcommit1}, \"Data\":\"$content_oldcommit1\"}]
41 \"CommitDate\":\"$(get_date -35d)\",
42 \"NewBranch\":\"branch1\",
44 {\"Filename\":\"file.dat\",\"Size\":${#content_oldcommit2}, \"Data\":\"$content_oldcommit2\"}]
47 \"CommitDate\":\"$(get_date -20d)\",
49 {\"Filename\":\"file.dat\",\"Size\":${#content_worktree1head}, \"Data\":\"$content_worktree1head\"}]
52 \"CommitDate\":\"$(get_date -30d)\",
53 \"ParentBranches\":[\"master\"],
54 \"NewBranch\":\"branch2\",
56 {\"Filename\":\"file.dat\",\"Size\":${#content_oldcommit3}, \"Data\":\"$content_oldcommit3\"}]
59 \"CommitDate\":\"$(get_date -15d)\",
61 {\"Filename\":\"file.dat\",\"Size\":${#content_worktree2head}, \"Data\":\"$content_worktree2head\"}]
64 \"CommitDate\":\"$(get_date -30d)\",
65 \"ParentBranches\":[\"master\"],
67 {\"Filename\":\"file.dat\",\"Size\":${#content_head}, \"Data\":\"$content_head\"}]
69 ]" | lfstest-testutils addcommits
71 # push everything so that's not a retention issue
72 git push origin master:master branch1:branch1 branch2:branch2
74 # don't keep any recent, just checkouts
75 git config lfs.fetchrecentrefsdays 0
76 git config lfs.fetchrecentremoterefs true
77 git config lfs.fetchrecentcommitsdays 0
79 # before worktree, everything except current checkout would be pruned
80 git lfs prune --dry-run 2>&1 | tee prune.log
81 grep "prune: 6 local object(s), 1 retained, done" prune.log
82 grep "prune: 5 file(s) would be pruned" prune.log
84 # now add worktrees on the other branches
85 git worktree add "../w1_$reponame" "branch1"
86 git worktree add "../w2_$reponame" "branch2"
87 # now should retain all 3 heads
88 git lfs prune --dry-run 2>&1 | tee prune.log
89 grep "prune: 6 local object(s), 3 retained, done" prune.log
90 grep "prune: 3 file(s) would be pruned" prune.log
92 # also check that the same result is obtained when inside worktree rather than main
94 git lfs prune --dry-run 2>&1 | tee prune.log
95 grep "prune: 6 local object(s), 3 retained, done" prune.log
96 grep "prune: 3 file(s) would be pruned" prune.log
98 # now remove a worktree & prove that frees up 1 head while keeping the other
100 rm -rf "../w1_$reponame"
101 git worktree prune # required to get git to tidy worktree metadata
102 git lfs prune --dry-run 2>&1 | tee prune.log
103 grep "prune: 6 local object(s), 2 retained, done" prune.log
104 grep "prune: 4 file(s) would be pruned" prune.log