import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.IOException;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Repository;
// The inner repository should be cleaned this time
assertTrue(forceCleanedFiles.contains(innerRepoName + "/"));
}
+
+ @Test
+ // To proof Bug 514434. No assertions, but before the bugfix
+ // this test was throwing Exceptions
+ public void testFilesShouldBeCleanedInSubSubFolders()
+ throws IOException, NoFilepatternException, GitAPIException {
+ writeTrashFile(".gitignore",
+ "/ignored-dir\n/sub-noclean/Ignored.txt\n/this_is_ok\n/this_is/not_ok\n");
+ git.add().addFilepattern(".gitignore").call();
+ git.commit().setMessage("adding .gitignore").call();
+ writeTrashFile("this_is_ok/more/subdirs/file.txt", "1");
+ writeTrashFile("this_is/not_ok/more/subdirs/file.txt", "2");
+ git.clean().setCleanDirectories(true).setIgnore(false).call();
+ }
}
StatusCommand command = new StatusCommand(repo);
Status status = command.call();
- Set<String> untrackedAndIgnoredFiles = new TreeSet<>(
- status.getUntracked());
- Set<String> untrackedAndIgnoredDirs = new TreeSet<>(
+ Set<String> untrackedFiles = new TreeSet<>(status.getUntracked());
+ Set<String> untrackedDirs = new TreeSet<>(
status.getUntrackedFolders());
FS fs = getRepository().getFS();
for (String p : status.getIgnoredNotInIndex()) {
File f = new File(repo.getWorkTree(), p);
- if (fs.isFile(f) || fs.isSymLink(f))
- untrackedAndIgnoredFiles.add(p);
- else if (fs.isDirectory(f))
- untrackedAndIgnoredDirs.add(p);
+ if (fs.isFile(f) || fs.isSymLink(f)) {
+ untrackedFiles.add(p);
+ } else if (fs.isDirectory(f)) {
+ untrackedDirs.add(p);
+ }
}
- Set<String> filtered = filterFolders(untrackedAndIgnoredFiles,
- untrackedAndIgnoredDirs);
+ Set<String> filtered = filterFolders(untrackedFiles, untrackedDirs);
Set<String> notIgnoredFiles = filterIgnorePaths(filtered,
status.getIgnoredNotInIndex(), true);
- Set<String> notIgnoredDirs = filterIgnorePaths(
- untrackedAndIgnoredDirs,
+ Set<String> notIgnoredDirs = filterIgnorePaths(untrackedDirs,
status.getIgnoredNotInIndex(), false);
for (String file : notIgnoredFiles)
if (new File(curFile, DOT_GIT).exists()) {
if (force) {
if (!dryRun) {
- FileUtils.delete(curFile, FileUtils.RECURSIVE);
+ FileUtils.delete(curFile, FileUtils.RECURSIVE
+ | FileUtils.SKIP_MISSING);
}
inFiles.add(path + "/"); //$NON-NLS-1$
}
} else {
if (!dryRun) {
- FileUtils.delete(curFile, FileUtils.RECURSIVE);
+ FileUtils.delete(curFile,
+ FileUtils.RECURSIVE | FileUtils.SKIP_MISSING);
}
inFiles.add(path + "/"); //$NON-NLS-1$
}
}
} else {
if (!dryRun) {
- FileUtils.delete(curFile, FileUtils.NONE);
+ FileUtils.delete(curFile, FileUtils.SKIP_MISSING);
}
inFiles.add(path);
}