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;
/**
private Collection<String> filepatterns;
+ private WorkingTreeIterator workingTreeIterator;
+
/**
*
* @param repo
return this;
}
+ /**
+ * 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
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));
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