summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src/org/eclipse
diff options
context:
space:
mode:
authorNed Twigg <ned.twigg@diffplug.com>2016-03-18 00:54:52 -0700
committerMatthias Sohn <matthias.sohn@sap.com>2016-08-30 22:21:05 +0200
commit34673f0536ce30305940a1031fde8923952127e8 (patch)
tree026b04b8494b5c4437644f78544f3417db628610 /org.eclipse.jgit.pgm/src/org/eclipse
parentd52bf2eee0eb8cd05d2c62c9b86e29db2616734c (diff)
downloadjgit-34673f0536ce30305940a1031fde8923952127e8.tar.gz
jgit-34673f0536ce30305940a1031fde8923952127e8.zip
Added a clean command.
Change-Id: I05d5392789b5b64e6ee44f678556cf25dc30d7ba Signed-off-by: Ned Twigg <ned.twigg@diffplug.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src/org/eclipse')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clean.java86
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java2
2 files changed, 88 insertions, 0 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clean.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clean.java
new file mode 100644
index 0000000000..fa94d2c1c4
--- /dev/null
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clean.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2016, Ned Twigg <ned.twigg@diffplug.com>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.pgm;
+
+import java.text.MessageFormat;
+import java.util.Set;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.pgm.internal.CLIText;
+import org.kohsuke.args4j.Option;
+
+@Command(common = true, usage = "usage_clean")
+class Clean extends TextBuiltin {
+ @Option(name = "-d", usage = "usage_removeUntrackedDirectories")
+ private boolean dirs = false;
+
+ @Option(name = "--force", aliases = {
+ "-f" }, usage = "usage_forceClean")
+ private boolean force = false;
+
+ @Option(name = "--dryRun", aliases = { "-n" })
+ private boolean dryRun = false;
+
+ @Override
+ protected void run() throws Exception {
+ try (Git git = new Git(db)) {
+ boolean requireForce = git.getRepository().getConfig()
+ .getBoolean("clean", "requireForce", true); //$NON-NLS-1$ //$NON-NLS-2$
+ if (requireForce && !(force || dryRun)) {
+ throw die(CLIText.fatalError(CLIText.get().cleanRequireForce));
+ }
+ // Note that CleanCommand's setForce(true) will delete
+ // .git folders. In the cgit cli, this behavior
+ // requires setting "-f" twice, not sure how to do
+ // this with args4j, so this feature is unimplemented
+ // for now.
+ Set<String> removedFiles = git.clean().setCleanDirectories(dirs)
+ .setDryRun(dryRun).call();
+ for (String removedFile : removedFiles) {
+ outw.println(MessageFormat.format(CLIText.get().removing,
+ removedFile));
+ }
+ }
+ }
+}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
index e99fe007d9..4148cf65da 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
@@ -125,6 +125,7 @@ public class CLIText extends TranslationBundle {
/***/ public String changesToBeCommitted;
/***/ public String checkoutConflict;
/***/ public String checkoutConflictPathLine;
+ /***/ public String cleanRequireForce;
/***/ public String clonedEmptyRepository;
/***/ public String cloningInto;
/***/ public String commitLabel;
@@ -246,6 +247,7 @@ public class CLIText extends TranslationBundle {
/***/ public String remoteMessage;
/***/ public String remoteRefObjectChangedIsNotExpectedOne;
/***/ public String remoteSideDoesNotSupportDeletingRefs;
+ /***/ public String removing;
/***/ public String repaint;
/***/ public String s3InvalidBucket;
/***/ public String serviceNotSupported;