diff options
author | Markus Duft <markus.duft@salomon.at> | 2012-07-13 08:31:10 +0200 |
---|---|---|
committer | Chris Aniszczyk <zx@twitter.com> | 2012-11-16 12:17:28 -0800 |
commit | f64237d5ff240cd62179f25fac7c40a9ffd5b2b8 (patch) | |
tree | 8107eab0f447f4ce5c9fb998f38d46de6647121c /org.eclipse.jgit.test | |
parent | fb33e8021878651b10f8c4e0e387cbdda01056e1 (diff) | |
download | jgit-f64237d5ff240cd62179f25fac7c40a9ffd5b2b8.tar.gz jgit-f64237d5ff240cd62179f25fac7c40a9ffd5b2b8.zip |
Adapt Status and CleanCommand to support cleaning directories
This adds the possibility to:
* retrieve untracked directories from the status
* instruct the CleanCommand to clean those directories.
* retrieve ignored paths from the status
* instruct the CleanCommand to leave those ignored paths alone
Bug: 338717
Change-Id: Ibed0459005a5e306c010b9932f5b5fd107fb5448
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java | 97 | ||||
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java | 5 |
2 files changed, 99 insertions, 3 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 5ded3bce12..0405783bbb 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 @@ -71,8 +71,18 @@ public class CleanCommandTest extends RepositoryTestCase { writeTrashFile("File2.txt", "Delete Me"); writeTrashFile("File3.txt", "Delete Me"); + // create files in sub-directories. + writeTrashFile("sub-noclean/File1.txt", "Hello world"); + writeTrashFile("sub-noclean/File2.txt", "Delete Me"); + writeTrashFile("sub-clean/File4.txt", "Delete Me"); + writeTrashFile("sub-noclean/Ignored.txt", "Ignored"); + writeTrashFile(".gitignore", "/ignored-dir\n/sub-noclean/Ignored.txt"); + writeTrashFile("ignored-dir/Ignored2.txt", "Ignored"); + // add and commit first file git.add().addFilepattern("File1.txt").call(); + git.add().addFilepattern("sub-noclean/File1.txt").call(); + git.add().addFilepattern(".gitignore").call(); git.commit().setMessage("Initial commit").call(); } @@ -90,9 +100,34 @@ public class CleanCommandTest extends RepositoryTestCase { status = git.status().call(); files = status.getUntracked(); - assertEquals(0, files.size()); + assertTrue(files.size() == 1); // one remains (directories not cleaned) + 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/File4.txt")); + } + + @Test + public void testCleanDirs() throws NoWorkTreeException, GitAPIException { + // create status + StatusCommand command = git.status(); + Status status = command.call(); + Set<String> files = status.getUntracked(); + assertTrue(files.size() > 0); + + // run clean + Set<String> cleanedFiles = git.clean().setCleanDirectories(true).call(); + + status = git.status().call(); + files = status.getUntracked(); + + assertTrue(files.size() == 0); 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/")); } @Test @@ -111,7 +146,7 @@ public class CleanCommandTest extends RepositoryTestCase { status = git.status().call(); files = status.getUntracked(); - assertEquals(1, files.size()); + assertTrue(files.size() == 3); assertTrue(cleanedFiles.contains("File3.txt")); assertFalse(cleanedFiles.contains("File2.txt")); } @@ -131,9 +166,65 @@ public class CleanCommandTest extends RepositoryTestCase { status = git.status().call(); files = status.getUntracked(); - assertEquals(2, files.size()); + assertEquals(4, files.size()); assertTrue(cleanedFiles.contains("File2.txt")); assertTrue(cleanedFiles.contains("File3.txt")); + assertTrue(!cleanedFiles.contains("sub-noclean/File1.txt")); + assertTrue(cleanedFiles.contains("sub-noclean/File2.txt")); + } + + @Test + public void testCleanDirsWithDryRun() throws NoWorkTreeException, + GitAPIException { + // create status + StatusCommand command = git.status(); + Status status = command.call(); + Set<String> files = status.getUntracked(); + assertTrue(files.size() > 0); + + // run clean + Set<String> cleanedFiles = git.clean().setDryRun(true) + .setCleanDirectories(true).call(); + + status = git.status().call(); + files = status.getUntracked(); + + assertTrue(files.size() == 4); + 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/")); + } + + @Test + public void testCleanWithDryRunAndNoIgnore() throws NoWorkTreeException, + GitAPIException { + // run clean + Set<String> cleanedFiles = git.clean().setDryRun(true).setIgnore(false) + .call(); + + Status status = git.status().call(); + Set<String> files = status.getIgnoredNotInIndex(); + + assertTrue(files.size() == 2); + assertTrue(cleanedFiles.contains("sub-noclean/Ignored.txt")); + assertTrue(!cleanedFiles.contains("ignored-dir/")); + } + + @Test + public void testCleanDirsWithDryRunAndNoIgnore() + throws NoWorkTreeException, GitAPIException { + // run clean + Set<String> cleanedFiles = git.clean().setDryRun(true).setIgnore(false) + .setCleanDirectories(true).call(); + + Status status = git.status().call(); + Set<String> files = status.getIgnoredNotInIndex(); + + assertTrue(files.size() == 2); + assertTrue(cleanedFiles.contains("sub-noclean/Ignored.txt")); + assertTrue(cleanedFiles.contains("ignored-dir/")); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java index c9a6048695..7856b0d871 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java @@ -44,6 +44,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 java.io.File; import java.io.IOException; @@ -125,6 +126,10 @@ public class StatusCommandTest extends RepositoryTestCase { assertEquals(set("a"), stat.getUntracked()); git.commit().setMessage("t").call(); + writeTrashFile("sub/a", "sub-file"); + stat = git.status().call(); + assertEquals(1, stat.getUntrackedFolders().size()); + assertTrue(stat.getUntrackedFolders().contains("sub")); } public static Set<String> set(String... elements) { |