View Javadoc
1   /*
2    * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.api;
11  
12  import static org.junit.Assert.assertTrue;
13  
14  import java.util.Date;
15  import java.util.Properties;
16  
17  import org.eclipse.jgit.junit.RepositoryTestCase;
18  import org.eclipse.jgit.util.GitDateParser;
19  import org.eclipse.jgit.util.SystemReader;
20  import org.junit.Before;
21  import org.junit.Test;
22  
23  public class GarbageCollectCommandTest extends RepositoryTestCase {
24  	private Git git;
25  
26  	@Override
27  	@Before
28  	public void setUp() throws Exception {
29  		super.setUp();
30  		git = new Git(db);
31  		String path = "a.txt";
32  		writeTrashFile(path, "content");
33  		git.add().addFilepattern(path).call();
34  		git.commit().setMessage("commit").call();
35  	}
36  
37  	@Test
38  	public void testGConeCommit() throws Exception {
39  		Date expire = GitDateParser.parse("now", null, SystemReader
40  				.getInstance().getLocale());
41  		Properties res = git.gc().setExpire(expire).call();
42  		assertTrue(res.size() == 8);
43  	}
44  
45  	@Test
46  	public void testGCmoreCommits() throws Exception {
47  		writeTrashFile("a.txt", "a couple of words for gc to pack");
48  		writeTrashFile("b.txt", "a couple of words for gc to pack 2");
49  		writeTrashFile("c.txt", "a couple of words for gc to pack 3");
50  		git.commit().setAll(true).setMessage("commit2").call();
51  		writeTrashFile("a.txt", "a couple of words for gc to pack more");
52  		writeTrashFile("b.txt", "a couple of words for gc to pack more 2");
53  		writeTrashFile("c.txt", "a couple of words for gc to pack more 3");
54  		git.commit().setAll(true).setMessage("commit3").call();
55  		Properties res = git
56  				.gc()
57  				.setExpire(
58  						GitDateParser.parse("now", null, SystemReader
59  								.getInstance().getLocale())).call();
60  		assertTrue(res.size() == 8);
61  	}
62  }