From 0ee89f01be7174d61ac3ac6af9805936b18818e5 Mon Sep 17 00:00:00 2001 From: Matthaus Owens Date: Fri, 29 Jul 2016 09:52:04 -0700 Subject: [PATCH] Add testCleanDirsWithSubmodule test to CleanCommandTest This commit adds some test coverage to cleaning a repository with a submodule, which did not previously exist. Bug: 498367 Change-Id: Ia5c4e4cc53488800dd486f8556dc57656783f1c4 Signed-off-by: Matthaus Owens --- .../eclipse/jgit/api/CleanCommandTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 7cca4b9e4..7daa9957d 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 @@ -45,6 +45,7 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.eclipse.jgit.lib.Constants.DOT_GIT_MODULES; import java.util.Set; import java.util.TreeSet; @@ -52,6 +53,7 @@ import java.util.TreeSet; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.Repository; import org.junit.Before; import org.junit.Test; @@ -227,4 +229,30 @@ public class CleanCommandTest extends RepositoryTestCase { assertTrue(cleanedFiles.contains("ignored-dir/")); } + @Test + public void testCleanDirsWithSubmodule() throws Exception { + SubmoduleAddCommand command = new SubmoduleAddCommand(db); + String path = "sub"; + command.setPath(path); + String uri = db.getDirectory().toURI().toString(); + command.setURI(uri); + Repository repo = command.call(); + repo.close(); + + Status beforeCleanStatus = git.status().call(); + assertTrue(beforeCleanStatus.getAdded().contains(DOT_GIT_MODULES)); + assertTrue(beforeCleanStatus.getAdded().contains(path)); + + Set cleanedFiles = git.clean().setCleanDirectories(true).call(); + + // The submodule should not be cleaned. + assertTrue(!cleanedFiles.contains(path + "/")); + + 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); + } }