1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.internal.storage.file;
45
46 import static org.junit.Assert.assertTrue;
47
48 import java.util.Collections;
49
50 import org.eclipse.jgit.junit.TestRepository.CommitBuilder;
51 import org.eclipse.jgit.lib.ObjectId;
52 import org.eclipse.jgit.lib.RefUpdate;
53 import org.eclipse.jgit.merge.MergeStrategy;
54 import org.eclipse.jgit.merge.Merger;
55 import org.eclipse.jgit.revwalk.RevCommit;
56 import org.eclipse.jgit.revwalk.RevTree;
57 import org.junit.Test;
58
59 public class GcBranchPrunedTest extends GcTestCase {
60
61 @Test
62 public void branch_historyNotPruned() throws Exception {
63 RevCommit tip = commitChain(10);
64 tr.branch("b").update(tip);
65 gc.setExpireAgeMillis(0);
66 fsTick();
67 gc.prune(Collections.<ObjectId> emptySet());
68 do {
69 assertTrue(repo.hasObject(tip));
70 tr.parseBody(tip);
71 RevTree t = tip.getTree();
72 assertTrue(repo.hasObject(t));
73 assertTrue(repo.hasObject(tr.get(t, "a")));
74 tip = tip.getParentCount() > 0 ? tip.getParent(0) : null;
75 } while (tip != null);
76 }
77
78 @Test
79 public void deleteBranch_historyPruned() throws Exception {
80 RevCommit tip = commitChain(10);
81 tr.branch("b").update(tip);
82 RefUpdate update = repo.updateRef("refs/heads/b");
83 update.setForceUpdate(true);
84 update.delete();
85 gc.setExpireAgeMillis(0);
86 fsTick();
87 gc.prune(Collections.<ObjectId> emptySet());
88 assertTrue(gc.getStatistics().numberOfLooseObjects == 0);
89 }
90
91 @Test
92 public void deleteMergedBranch_historyNotPruned() throws Exception {
93 RevCommit parent = tr.commit().create();
94 RevCommit b1Tip = tr.branch("b1").commit().parent(parent).add("x", "x")
95 .create();
96 RevCommit b2Tip = tr.branch("b2").commit().parent(parent).add("y", "y")
97 .create();
98
99
100 Merger merger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(repo);
101 merger.merge(b1Tip, b2Tip);
102 CommitBuilder cb = tr.commit();
103 cb.parent(b1Tip).parent(b2Tip);
104 cb.setTopLevelTree(merger.getResultTreeId());
105 RevCommit mergeCommit = cb.create();
106 RefUpdate u = repo.updateRef("refs/heads/b1");
107 u.setNewObjectId(mergeCommit);
108 u.update();
109
110 RefUpdate update = repo.updateRef("refs/heads/b2");
111 update.setForceUpdate(true);
112 update.delete();
113
114 gc.setExpireAgeMillis(0);
115 fsTick();
116 gc.prune(Collections.<ObjectId> emptySet());
117 assertTrue(repo.hasObject(b2Tip));
118 }
119 }