@ -44,11 +44,14 @@
package org.eclipse.jgit.pgm ;
import java.io.File ;
import java.io.IOException ;
import java.text.MessageFormat ;
import java.util.Collection ;
import org.eclipse.jgit.api.CloneCommand ;
import org.eclipse.jgit.api.Git ;
import org.eclipse.jgit.api.errors.InvalidRemoteException ;
import org.eclipse.jgit.lib.AnyObjectId ;
import org.eclipse.jgit.lib.Constants ;
import org.eclipse.jgit.lib.TextProgressMonitor ;
import org.eclipse.jgit.pgm.internal.CLIText ;
@ -58,7 +61,7 @@ import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option ;
@Command ( common = true , usage = "usage_cloneRepositoryIntoNewDir" )
class Clone extends AbstractFetchCommand {
class Clone extends AbstractFetchCommand implements CloneCommand . Callback {
@Option ( name = "--origin" , aliases = { "-o" } , metaVar = "metaVar_remoteName" , usage = "usage_useNameInsteadOfOriginToTrackUpstream" )
private String remoteName = Constants . DEFAULT_REMOTE_NAME ;
@ -74,6 +77,9 @@ class Clone extends AbstractFetchCommand {
@Option ( name = "--quiet" , usage = "usage_quiet" )
private Boolean quiet ;
@Option ( name = "--recurse-submodules" , usage = "usage_recurseSubmodules" )
private boolean cloneSubmodules ;
@Argument ( index = 0 , required = true , metaVar = "metaVar_uriish" )
private String sourceUri ;
@ -109,13 +115,15 @@ class Clone extends AbstractFetchCommand {
CloneCommand command = Git . cloneRepository ( ) ;
command . setURI ( sourceUri ) . setRemote ( remoteName ) . setBare ( isBare )
. setNoCheckout ( noCheckout ) . setBranch ( branch ) ;
. setNoCheckout ( noCheckout ) . setBranch ( branch )
. setCloneSubmodules ( cloneSubmodules ) ;
command . setGitDir ( gitdir = = null ? null : new File ( gitdir ) ) ;
command . setDirectory ( localNameF ) ;
boolean msgs = quiet = = null | | ! quiet . booleanValue ( ) ;
if ( msgs ) {
command . setProgressMonitor ( new TextProgressMonitor ( errw ) ) ;
command . setProgressMonitor ( new TextProgressMonitor ( errw ) )
. setCallback ( this ) ;
outw . println ( MessageFormat . format (
CLIText . get ( ) . cloningInto , localName ) ) ;
outw . flush ( ) ;
@ -136,4 +144,39 @@ class Clone extends AbstractFetchCommand {
outw . flush ( ) ;
}
}
@Override
public void initializedSubmodules ( Collection < String > submodules ) {
try {
for ( String submodule : submodules ) {
outw . println ( MessageFormat
. format ( CLIText . get ( ) . submoduleRegistered , submodule ) ) ;
}
outw . flush ( ) ;
} catch ( IOException e ) {
// ignore
}
}
@Override
public void cloningSubmodule ( String path ) {
try {
outw . println ( MessageFormat . format (
CLIText . get ( ) . cloningInto , path ) ) ;
outw . flush ( ) ;
} catch ( IOException e ) {
// ignore
}
}
@Override
public void checkingOut ( AnyObjectId commit , String path ) {
try {
outw . println ( MessageFormat . format ( CLIText . get ( ) . checkingOut ,
path , commit . getName ( ) ) ) ;
outw . flush ( ) ;
} catch ( IOException e ) {
// ignore
}
}
}