1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.pgm;
12
13 import java.io.IOException;
14 import java.text.MessageFormat;
15 import java.util.Set;
16
17 import org.eclipse.jgit.api.Git;
18 import org.eclipse.jgit.api.errors.GitAPIException;
19 import org.eclipse.jgit.errors.NoWorkTreeException;
20 import org.eclipse.jgit.pgm.internal.CLIText;
21 import org.kohsuke.args4j.Option;
22
23 @Command(common = true, usage = "usage_Clean")
24 class Clean extends TextBuiltin {
25 @Option(name = "-d", usage = "usage_removeUntrackedDirectories")
26 private boolean dirs = false;
27
28 @Option(name = "--force", aliases = {
29 "-f" }, usage = "usage_forceClean")
30 private boolean force = false;
31
32 @Option(name = "--dryRun", aliases = { "-n" })
33 private boolean dryRun = false;
34
35
36 @Override
37 protected void run() {
38 try (Git git = new Git(db)) {
39 boolean requireForce = git.getRepository().getConfig()
40 .getBoolean("clean", "requireForce", true);
41 if (requireForce && !(force || dryRun)) {
42 throw die(CLIText.fatalError(CLIText.get().cleanRequireForce));
43 }
44
45
46
47
48
49 Set<String> removedFiles = git.clean().setCleanDirectories(dirs)
50 .setDryRun(dryRun).call();
51 for (String removedFile : removedFiles) {
52 outw.println(MessageFormat.format(CLIText.get().removing,
53 removedFile));
54 }
55 } catch (NoWorkTreeException | GitAPIException | IOException e) {
56 throw die(e.getMessage(), e);
57 }
58 }
59 }