Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] GarbageCollectCommand does not prune unreferenced commit

You are right of course, the shown code isn't quite what I tired. Sorry for the confusion. If I change it to 'unreference' the orphan commit the result is still the same.

The correct version would reset HEAD to the previous commit so that 'orphan' is actually unreferenced like this:

@Test
public void testPruneOldOrphanCommit() throws Exception {
ObjectId initial = git.getRepository().resolve("HEAD");
RevCommit orphan = git.commit().setMessage("orphan").call();
changeLastModified(orphan, subtractDays(new Date(), 365));
RefUpdate refUpdate = git.getRepository()
.updateRef("refs/heads/master");
refUpdate.setNewObjectId(initial);
refUpdate.forceUpdate();

git.gc().setExpire(new Date()).call();

assertNull(git.getRepository().resolve(orphan.name()));
}




From: Shawn Pearce <spearce@xxxxxxxxxxx>
To: R�diger Herrmann <ruediger.herrmann@xxxxxx>
Cc: "jgit-dev@xxxxxxxxxxx" <jgit-dev@xxxxxxxxxxx>
Sent: Wednesday, April 6, 2016 10:54 PM
Subject: Re: [jgit-dev] GarbageCollectCommand does not prune unreferenced commit

On Wed, Apr 6, 2016 at 10:48 AM, R�diger Herrmann

<ruediger.herrmann@xxxxxx> wrote:
> 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();


Doesn't this update HEAD to point to the commit it made? In which case
its reachable and cannot be garbage collected.


Back to the top