aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2013-07-19 13:37:58 +0200
committerChris Aniszczyk <caniszczyk@gmail.com>2013-07-21 21:39:53 -0500
commit06dd0e9e27a342f74ec97648ab1fbf101af383a4 (patch)
tree0b1235cca24e9b048be7b727893a94d4aca527bf /org.eclipse.jgit/src/org/eclipse
parentf5be93d003759f6c933d33d56c8a18fa9e66766b (diff)
downloadjgit-06dd0e9e27a342f74ec97648ab1fbf101af383a4.tar.gz
jgit-06dd0e9e27a342f74ec97648ab1fbf101af383a4.zip
Add path option to StatusCommand
Allow filtering of the status. Only files which match given paths are inspected and only their state is reported. Change-Id: I3c4b1b46bf297cd4ebdb4997cfa14c8752a36411 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java
index b3e112fc6a..182ffa84b1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StatusCommand.java
@@ -43,6 +43,8 @@
package org.eclipse.jgit.api;
import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -52,6 +54,7 @@ import org.eclipse.jgit.lib.IndexDiff;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
+import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
/**
* A class used to execute a {@code Status} command. It has setters for all
@@ -65,6 +68,7 @@ import org.eclipse.jgit.treewalk.WorkingTreeIterator;
*/
public class StatusCommand extends GitCommand<Status> {
private WorkingTreeIterator workingTreeIt;
+ private List<String> paths = null;
/**
* @param repo
@@ -74,6 +78,36 @@ public class StatusCommand extends GitCommand<Status> {
}
/**
+ * Show only the status of files which match the given paths. The path must
+ * either name a file or a directory exactly. All paths are always relative
+ * to the repository root. If a directory is specified all files recursively
+ * underneath that directory are matched. If this method is called multiple
+ * times then the status of those files is reported which match at least one
+ * of the given paths. Note that regex expressions or wildcards are not
+ * supported.
+ *
+ * @param path
+ * a path is relative to the top level of the repository
+ * @return {@code this}
+ */
+ public StatusCommand addPath(String path) {
+ if (paths == null)
+ paths = new LinkedList<String>();
+ paths.add(path);
+ return this;
+ }
+
+ /**
+ * Returns the paths filtering this status.
+ *
+ * @return the paths for which the status is shown or <code>null</code> if
+ * the complete status for the whole repo is shown.
+ */
+ public List<String> getPaths() {
+ return paths;
+ }
+
+ /**
* Executes the {@code Status} command with all the options and parameters
* collected by the setter methods of this class. Each instance of this
* class should only be used for one invocation of the command. Don't call
@@ -88,6 +122,8 @@ public class StatusCommand extends GitCommand<Status> {
try {
IndexDiff diff = new IndexDiff(repo, Constants.HEAD, workingTreeIt);
+ if (paths != null)
+ diff.setFilter(PathFilterGroup.createFromStrings(paths));
diff.diff();
return new Status(diff);
} catch (IOException e) {