Hi All,
I found the GC command does not work as I would expect and so I am asking for your help to clarify what/who is wrong here. My understand is that an unreferenced commit that is 'old' enough would be pruned, but apparently the commit remains in the repository after garbage collection.
This test probably illustrates best what I am trying (please paste into GarbageCollectCommandTest to run it). Since the 'orphan' commit object is marked as one year old and 'setExpire' is set to now, I thought the commit would be pruned but according to the assert, it is not.
@Test
public void testPruneOldOrphanCommit() throws Exception {
RevCommit orphan = git.commit().setMessage("orphan").call();
changeLastModified(orphan, subtractDays(new Date(), 365));
git.gc().setExpire(new Date()).call();
assertNull(git.getRepository().resolve(orphan.name()));
}
private static Date subtractDays(Date date, int days) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, days * (-1));
return calendar.getTime();
}
private void changeLastModified(ObjectId commitId, Date date) {
File objectsDirectory = new File(git.getRepository().getDirectory(),
"objects");
File commitObjectDirectory = new File(objectsDirectory,
commitId.name().substring(0, 2));
File commitObjectFile = new File(commitObjectDirectory,
commitId.name().substring(2));
commitObjectFile.setLastModified(date.getTime());
}
I would be grateful if someone could shed some light onto this issue.
Best,
Rüdiger