@ -58,6 +58,7 @@ import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.Repository ;
import org.eclipse.jgit.lib.Repository ;
import org.eclipse.jgit.treewalk.FileTreeIterator ;
import org.eclipse.jgit.treewalk.FileTreeIterator ;
import org.eclipse.jgit.treewalk.TreeWalk ;
import org.eclipse.jgit.treewalk.TreeWalk ;
import org.eclipse.jgit.treewalk.WorkingTreeIterator ;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup ;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup ;
/ * *
/ * *
@ -73,6 +74,8 @@ public class AddCommand extends GitCommand<DirCache> {
private Collection < String > filepatterns ;
private Collection < String > filepatterns ;
private WorkingTreeIterator workingTreeIterator ;
/ * *
/ * *
*
*
* @param repo
* @param repo
@ -96,6 +99,16 @@ public class AddCommand extends GitCommand<DirCache> {
return this ;
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
* 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
* be used for one invocation of the command . Don ' t call this method twice
@ -122,8 +135,9 @@ public class AddCommand extends GitCommand<DirCache> {
final TreeWalk tw = new TreeWalk ( repo ) ;
final TreeWalk tw = new TreeWalk ( repo ) ;
tw . reset ( ) ;
tw . reset ( ) ;
tw . addTree ( new DirCacheBuildIterator ( builder ) ) ;
tw . addTree ( new DirCacheBuildIterator ( builder ) ) ;
FileTreeIterator fileTreeIterator = new FileTreeIterator ( repo ) ;
if ( workingTreeIterator = = null )
tw . addTree ( fileTreeIterator ) ;
workingTreeIterator = new FileTreeIterator ( repo ) ;
tw . addTree ( workingTreeIterator ) ;
tw . setRecursive ( true ) ;
tw . setRecursive ( true ) ;
if ( ! addAll )
if ( ! addAll )
tw . setFilter ( PathFilterGroup . createFromStrings ( filepatterns ) ) ;
tw . setFilter ( PathFilterGroup . createFromStrings ( filepatterns ) ) ;
@ -134,7 +148,7 @@ public class AddCommand extends GitCommand<DirCache> {
String path = tw . getPathString ( ) ;
String path = tw . getPathString ( ) ;
final File file = new File ( repo . getWorkDir ( ) , path ) ;
final File file = new File ( repo . getWorkDir ( ) , path ) ;
File TreeIterator f = tw . getTree ( 1 , File TreeIterator. class ) ;
Working TreeIterator f = tw . getTree ( 1 , Working TreeIterator. class ) ;
if ( tw . getTree ( 0 , DirCacheIterator . class ) = = null & &
if ( tw . getTree ( 0 , DirCacheIterator . class ) = = null & &
f ! = null & & f . isEntryIgnored ( ) ) {
f ! = null & & f . isEntryIgnored ( ) ) {
// file is not in index but is ignored, do nothing
// file is not in index but is ignored, do nothing