You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GarbageCollectCommandTest.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. import static org.junit.Assert.assertTrue;
  12. import java.util.Date;
  13. import java.util.Properties;
  14. import org.eclipse.jgit.junit.RepositoryTestCase;
  15. import org.eclipse.jgit.util.GitDateParser;
  16. import org.eclipse.jgit.util.SystemReader;
  17. import org.junit.Before;
  18. import org.junit.Test;
  19. public class GarbageCollectCommandTest extends RepositoryTestCase {
  20. private Git git;
  21. @Override
  22. @Before
  23. public void setUp() throws Exception {
  24. super.setUp();
  25. git = new Git(db);
  26. String path = "a.txt";
  27. writeTrashFile(path, "content");
  28. git.add().addFilepattern(path).call();
  29. git.commit().setMessage("commit").call();
  30. }
  31. @Test
  32. public void testGConeCommit() throws Exception {
  33. Date expire = GitDateParser.parse("now", null, SystemReader
  34. .getInstance().getLocale());
  35. Properties res = git.gc().setExpire(expire).call();
  36. assertTrue(res.size() == 7);
  37. }
  38. @Test
  39. public void testGCmoreCommits() throws Exception {
  40. writeTrashFile("a.txt", "a couple of words for gc to pack");
  41. writeTrashFile("b.txt", "a couple of words for gc to pack 2");
  42. writeTrashFile("c.txt", "a couple of words for gc to pack 3");
  43. git.commit().setAll(true).setMessage("commit2").call();
  44. writeTrashFile("a.txt", "a couple of words for gc to pack more");
  45. writeTrashFile("b.txt", "a couple of words for gc to pack more 2");
  46. writeTrashFile("c.txt", "a couple of words for gc to pack more 3");
  47. git.commit().setAll(true).setMessage("commit3").call();
  48. Properties res = git
  49. .gc()
  50. .setExpire(
  51. GitDateParser.parse("now", null, SystemReader
  52. .getInstance().getLocale())).call();
  53. assertTrue(res.size() == 7);
  54. }
  55. }