summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java19
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java71
4 files changed, 78 insertions, 37 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 760acbb57f..a660a5292b 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
@@ -113,4 +113,23 @@ public class CleanCommandTest extends RepositoryTestCase {
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"));
+ }
+
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
index 4d2b241dcb..8031769204 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
@@ -51,6 +51,7 @@ import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -74,6 +75,14 @@ public class GitConstructionTest extends RepositoryTestCase {
addRepoToClose(bareRepo);
}
+ @Override
+ @After
+ public void tearDown() throws Exception {
+ db.close();
+ bareRepo.close();
+ super.tearDown();
+ }
+
@Test
public void testWrap() {
Git git = Git.wrap(db);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java
index d0d40c4679..e31f119cb2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CleanCommand.java
@@ -64,6 +64,8 @@ public class CleanCommand extends GitCommand<Set<String>> {
private Set<String> paths = Collections.emptySet();
+ private boolean dryRun;
+
/**
* @param repo
*/
@@ -86,7 +88,8 @@ public class CleanCommand extends GitCommand<Set<String>> {
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);
}
}
@@ -108,4 +111,15 @@ public class CleanCommand extends GitCommand<Set<String>> {
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;
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
index 8fe7b2aa51..8534724cbb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
@@ -202,43 +202,42 @@ public class URIish implements Serializable {
if (matcher.matches()) {
scheme = matcher.group(1);
path = cleanLeadingSlashes(matcher.group(2), scheme);
- } else {
- matcher = FULL_URI.matcher(s);
- if (matcher.matches()) {
- scheme = matcher.group(1);
- user = matcher.group(2);
- pass = matcher.group(3);
- host = matcher.group(4);
- if (matcher.group(5) != null)
- port = Integer.parseInt(matcher.group(5));
- path = cleanLeadingSlashes(
- n2e(matcher.group(6)) + n2e(matcher.group(7)),
- scheme);
- } else {
- matcher = RELATIVE_SCP_URI.matcher(s);
- if (matcher.matches()) {
- user = matcher.group(1);
- pass = matcher.group(2);
- host = matcher.group(3);
- path = matcher.group(4);
- } else {
- matcher = ABSOLUTE_SCP_URI.matcher(s);
- if (matcher.matches()) {
- user = matcher.group(1);
- pass = matcher.group(2);
- host = matcher.group(3);
- path = matcher.group(4);
- } else {
- matcher = LOCAL_FILE.matcher(s);
- if (matcher.matches()) {
- path = matcher.group(1);
- } else
- throw new URISyntaxException(s,
- JGitText.get().cannotParseGitURIish);
- }
- }
- }
+ return;
+ }
+ matcher = FULL_URI.matcher(s);
+ if (matcher.matches()) {
+ scheme = matcher.group(1);
+ user = matcher.group(2);
+ pass = matcher.group(3);
+ host = matcher.group(4);
+ if (matcher.group(5) != null)
+ port = Integer.parseInt(matcher.group(5));
+ path = cleanLeadingSlashes(
+ n2e(matcher.group(6)) + n2e(matcher.group(7)), scheme);
+ return;
+ }
+ matcher = RELATIVE_SCP_URI.matcher(s);
+ if (matcher.matches()) {
+ user = matcher.group(1);
+ pass = matcher.group(2);
+ host = matcher.group(3);
+ path = matcher.group(4);
+ return;
+ }
+ matcher = ABSOLUTE_SCP_URI.matcher(s);
+ if (matcher.matches()) {
+ user = matcher.group(1);
+ pass = matcher.group(2);
+ host = matcher.group(3);
+ path = matcher.group(4);
+ return;
+ }
+ matcher = LOCAL_FILE.matcher(s);
+ if (matcher.matches()) {
+ path = matcher.group(1);
+ return;
}
+ throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish);
}
private String n2e(String s) {