@ -303,18 +303,25 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
}
private List < RefSpec > calculateRefSpecs ( boolean fetchAll , String dst ) {
RefSpec wcr s = new RefSpec ( ) ;
wcrs = wcr s. setForceUpdate ( true ) ;
wcrs = wcr s. setSourceDestination ( Constants . R_HEADS + '*' , dst ) ;
RefSpec head s = new RefSpec ( ) ;
heads = head s. setForceUpdate ( true ) ;
heads = head s. setSourceDestination ( Constants . R_HEADS + '*' , dst ) ;
List < RefSpec > specs = new ArrayList < > ( ) ;
if ( ! fetchAll ) {
RefSpec tags = new RefSpec ( ) ;
tags = tags . setForceUpdate ( true ) ;
tags = tags . setSourceDestination ( Constants . R_TAGS + '*' ,
Constants . R_TAGS + '*' ) ;
for ( String selectedRef : branchesToClone ) {
if ( wcrs . matchSource ( selectedRef ) ) {
specs . add ( wcrs . expandFromSource ( selectedRef ) ) ;
if ( heads . matchSource ( selectedRef ) ) {
specs . add ( heads . expandFromSource ( selectedRef ) ) ;
} else if ( tags . matchSource ( selectedRef ) ) {
specs . add ( tags . expandFromSource ( selectedRef ) ) ;
}
}
} else {
specs . add ( wcrs ) ;
// We'll fetch the tags anyway.
specs . add ( heads ) ;
}
return specs ;
}
@ -590,11 +597,15 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
}
/ * *
* Set whether all branches have to be fetched
* Set whether all branches have to be fetched .
* < p >
* If { @code false } , use { @link # setBranchesToClone ( Collection ) } to define
* what will be cloned . If neither are set , all branches will be cloned .
* < / p >
*
* @param cloneAllBranches
* true when all branches have to be fetched ( indicates wildcard
* in created fetch refspec ) , false otherwise .
* { @code true } when all branches have to be fetched ( indicates
* wildcard in created fetch refspec ) , { @code false } otherwise .
* @return { @code this }
* /
public CloneCommand setCloneAllBranches ( boolean cloneAllBranches ) {
@ -616,12 +627,17 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
}
/ * *
* Set branches to clone
* Set the branches or tags to clone .
* < p >
* This is ignored if { @link # setCloneAllBranches ( boolean )
* setCloneAllBranches ( true ) } is used . If { @code branchesToClone } is
* { @code null } or empty , it ' s also ignored and all branches will be cloned .
* < / p >
*
* @param branchesToClone
* collection of branches to clone . Ignored when allSelected is
* true . Must be specified as full ref names ( e . g .
* < code > refs / heads / master < / code > ) .
* collection of branches to clone . Must be specified as full ref
* names ( e . g . { @code refs / heads / master } or
* { @code refs / tags / v1 . 0 . 0 } ) .
* @return { @code this }
* /
public CloneCommand setBranchesToClone ( Collection < String > branchesToClone ) {