diff options
author | Matthaus Owens <matthaus@puppetlabs.com> | 2016-07-29 15:21:20 -0700 |
---|---|---|
committer | Matthaus Owens <matthaus@puppetlabs.com> | 2016-08-04 13:38:52 -0700 |
commit | e1ffab1cac55179011777b9a60bac447b0a62ccf (patch) | |
tree | 157fc203415b4f85e86f1e75ee026451138e8af5 /org.eclipse.jgit.test | |
parent | 0ee89f01be7174d61ac3ac6af9805936b18818e5 (diff) | |
download | jgit-e1ffab1cac55179011777b9a60bac447b0a62ccf.tar.gz jgit-e1ffab1cac55179011777b9a60bac447b0a62ccf.zip |
Skip cleaning inner repositories by default in CleanCommand
Previously jgit would attempt to clean git repositories that had not
been committed by calling a non-recursive delete on them, which would
fail as they are directories. This commit addresses that issue in the
following ways.
Repositories are skipped in a default clean, similarly to cgit and only
cleaned when the force flag is applied. When the force flag is applied
repositories are deleted using a recursive delete call. The force flag
and setForce method are added here to CleanCommand to support this
change.
Bug: 498367
Change-Id: Ib6cfff65a033d0d0f76395060bf76719e13fc467
Signed-off-by: Matthaus Owens <matthaus@puppetlabs.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java index 7daa9957dc..68f5dd1e0d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java @@ -47,6 +47,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.eclipse.jgit.lib.Constants.DOT_GIT_MODULES; +import java.io.File; import java.util.Set; import java.util.TreeSet; @@ -255,4 +256,43 @@ public class CleanCommandTest extends RepositoryTestCase { assertTrue(cleanedFiles.contains("sub-clean/")); assertTrue(cleanedFiles.size() == 4); } + + @Test + public void testCleanDirsWithRepository() throws Exception { + // Set up a repository inside the outer repository + String innerRepoName = "inner-repo"; + File innerDir = new File(trash, innerRepoName); + innerDir.mkdir(); + InitCommand initRepoCommand = new InitCommand(); + initRepoCommand.setDirectory(innerDir); + initRepoCommand.call(); + + Status beforeCleanStatus = git.status().call(); + Set<String> untrackedFolders = beforeCleanStatus.getUntrackedFolders(); + Set<String> untrackedFiles = beforeCleanStatus.getUntracked(); + + // The inner repository should be listed as an untracked file + assertTrue(untrackedFiles.contains(innerRepoName)); + + // The inner repository should not be listed as an untracked folder + assertTrue(!untrackedFolders.contains(innerRepoName)); + + Set<String> cleanedFiles = git.clean().setCleanDirectories(true).call(); + + // The inner repository should not be cleaned. + assertTrue(!cleanedFiles.contains(innerRepoName + "/")); + + assertTrue(cleanedFiles.contains("File2.txt")); + assertTrue(cleanedFiles.contains("File3.txt")); + assertTrue(!cleanedFiles.contains("sub-noclean/File1.txt")); + assertTrue(cleanedFiles.contains("sub-noclean/File2.txt")); + assertTrue(cleanedFiles.contains("sub-clean/")); + assertTrue(cleanedFiles.size() == 4); + + Set<String> forceCleanedFiles = git.clean().setCleanDirectories(true) + .setForce(true).call(); + + // The inner repository should be cleaned this time + assertTrue(forceCleanedFiles.contains(innerRepoName + "/")); + } } |