assertTrue(!cleanedFiles.contains("File2.txt"));
}
+ @Test
+ public void testCleanWithDryRun() throws NoWorkTreeException, IOException {
+ // 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).call();
+
+ status = git.status().call();
+ files = status.getUntracked();
+
+ assertTrue(files.size() == 2);
+ assertTrue(cleanedFiles.contains("File2.txt"));
+ assertTrue(cleanedFiles.contains("File3.txt"));
+ }
+
}
private Set<String> paths = Collections.emptySet();
+ private boolean dryRun;
+
/**
* @param repo
*/
Status status = command.call();
for (String file : status.getUntracked()) {
if (paths.isEmpty() || paths.contains(file)) {
- FileUtils.delete(new File(repo.getWorkTree(), file));
+ if (!dryRun)
+ FileUtils.delete(new File(repo.getWorkTree(), file));
files.add(file);
}
}
return this;
}
+ /**
+ * If dryRun is set, the paths in question will not actually be deleted.
+ *
+ * @param dryRun
+ * whether to do a dry run or not
+ * @return {@code this}
+ */
+ public CleanCommand setDryRun(boolean dryRun) {
+ this.dryRun = dryRun;
+ return this;
+ }
}