diff options
author | Stefan Lay <stefan.lay@sap.com> | 2010-07-22 14:57:00 +0200 |
---|---|---|
committer | Stefan Lay <stefan.lay@sap.com> | 2010-07-22 14:57:00 +0200 |
commit | ab062caa2255054cca413985bbaa3ad7c1c9c383 (patch) | |
tree | 52e560f48586eddfd7561dde8b901cfda0e78751 | |
parent | 88957f6c5ad3c6e74a8b6d5fcd82006fae9c60a0 (diff) | |
download | jgit-ab062caa2255054cca413985bbaa3ad7c1c9c383.tar.gz jgit-ab062caa2255054cca413985bbaa3ad7c1c9c383.zip |
Allow client of Add command to set a WorkingTreeIterator
This is e.g. useful when a client of the AddCommand has
additional rules to ignore files. In Eclipse a resource can
be set to derived or be excluded by preferences.
Change-Id: I6c47e54a1ce26315faf5ed0723298ad2c2db197c
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java index 8dbbb4063f..157b85f9c9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/AddCommand.java @@ -58,6 +58,7 @@ import org.eclipse.jgit.lib.ObjectWriter; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.TreeWalk; +import org.eclipse.jgit.treewalk.WorkingTreeIterator; import org.eclipse.jgit.treewalk.filter.PathFilterGroup; /** @@ -73,6 +74,8 @@ public class AddCommand extends GitCommand<DirCache> { private Collection<String> filepatterns; + private WorkingTreeIterator workingTreeIterator; + /** * * @param repo @@ -97,6 +100,16 @@ public class AddCommand extends GitCommand<DirCache> { } /** + * Allow clients to provide their own implementation of a FileTreeIterator + * @param f + * @return {@code this} + */ + public AddCommand setWorkingTreeIterator(WorkingTreeIterator f) { + workingTreeIterator = f; + return this; + } + + /** * Executes the {@code Add} command. Each instance of this class should only * be used for one invocation of the command. Don't call this method twice * on an instance. @@ -122,8 +135,9 @@ public class AddCommand extends GitCommand<DirCache> { final TreeWalk tw = new TreeWalk(repo); tw.reset(); tw.addTree(new DirCacheBuildIterator(builder)); - FileTreeIterator fileTreeIterator = new FileTreeIterator(repo); - tw.addTree(fileTreeIterator); + if (workingTreeIterator == null) + workingTreeIterator = new FileTreeIterator(repo); + tw.addTree(workingTreeIterator); tw.setRecursive(true); if (!addAll) tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); @@ -134,7 +148,7 @@ public class AddCommand extends GitCommand<DirCache> { String path = tw.getPathString(); final File file = new File(repo.getWorkDir(), path); - FileTreeIterator f = tw.getTree(1, FileTreeIterator.class); + WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class); if (tw.getTree(0, DirCacheIterator.class) == null && f != null && f.isEntryIgnored()) { // file is not in index but is ignored, do nothing |