Skip to content

Commit

Permalink
Add recursive options to nextflow run/clone/pull commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Akira Sekiguchi committed Jun 9, 2020
1 parent 8f475f4 commit 8447dfd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class CmdClone extends CmdBase implements HubOptions {
@Parameter(names='-r', description = 'Revision to clone - It can be a git branch, tag or revision number')
String revision

@Parameter(names=['-recursive','-recurse-submodules'], description = 'initialize submodules in the clone', arity = 0)
boolean recurse_submodules

@Override
final String getName() { NAME }

Expand All @@ -63,7 +66,7 @@ class CmdClone extends CmdBase implements HubOptions {

manager.checkValidRemoteRepo()
print "Cloning ${manager.project}${revision ? ':'+revision:''} ..."
manager.clone(target, revision)
manager.clone(target, revision, recurse_submodules)
print "\r"
println "${manager.project} cloned to: $target"
}
Expand Down
6 changes: 4 additions & 2 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdPull.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CmdPull extends CmdBase implements HubOptions {
@Parameter(names=['-r','-revision'], description = 'Revision of the project to run (either a git branch, tag or commit SHA number)')
String revision

@Parameter(names='-recursive', description = 'control recursive fetching of submodules', arity = 0)
boolean recurse_submodules


@Override
Expand Down Expand Up @@ -71,8 +73,8 @@ class CmdPull extends CmdBase implements HubOptions {
log.info "Checking $it ..."
def manager = new AssetManager(it, this)

def result = manager.download(revision)
manager.updateModules()
def result = manager.download(recurse_submodules, revision)
manager.updateModules(recurse_submodules)

def scriptFile = manager.getScriptFile()
String message = !result ? " done" : " $result"
Expand Down
7 changes: 5 additions & 2 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class CmdRun extends CmdBase implements HubOptions {
@Parameter(names=['-bucket-dir'], description = 'Remote bucket where intermediate result files are stored')
String bucketDir

@Parameter(names=['-recursive','-recurse-submodules'], description = 'Try to download submodules recursively if those do not exist', arity = 0)
boolean recurse_submodules

/**
* Defines the parameters to be passed to the pipeline script
*/
Expand Down Expand Up @@ -336,15 +339,15 @@ class CmdRun extends CmdBase implements HubOptions {
if( offline )
throw new AbortOperationException("Unknown project `$repo` -- NOTE: automatic download from remote repositories is disabled")
log.info "Pulling $repo ..."
def result = manager.download()
def result = manager.download(recurse_submodules)
if( result )
log.info " $result"
checkForUpdate = false
}
// checkout requested revision
try {
manager.checkout(revision)
manager.updateModules()
manager.updateModules(recurse_submodules)
def scriptFile = manager.getScriptFile()
log.info "Launching `$repo` [$runName] - revision: ${scriptFile.revisionInfo}"
if( checkForUpdate && !offline )
Expand Down
16 changes: 10 additions & 6 deletions modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class AssetManager {
* @param revision The revision to download
* @result A message representing the operation result
*/
def download(String revision=null) {
def download(boolean recurse_submodules = false, String revision=null) {
assert project

/*
Expand All @@ -591,7 +591,7 @@ class AssetManager {
clone
.setURI(cloneURL)
.setDirectory(localPath)
.setCloneSubmodules(true)
.setCloneSubmodules(recurse_submodules)
.call()

// return status message
Expand Down Expand Up @@ -652,7 +652,7 @@ class AssetManager {
* @param directory The folder when the pipeline will be cloned
* @param revision The revision to be cloned. It can be a branch, tag, or git revision number
*/
void clone(File directory, String revision = null) {
void clone(File directory, String revision = null, boolean recurse_submodules) {

def clone = Git.cloneRepository()
def uri = getGitRepositoryUrl()
Expand All @@ -663,7 +663,7 @@ class AssetManager {

clone.setURI(uri)
clone.setDirectory(directory)
clone.setCloneSubmodules(true)
clone.setCloneSubmodules(recurse_submodules)
if( provider.hasCredentials() )
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(provider.user, provider.password))

Expand Down Expand Up @@ -939,7 +939,7 @@ class AssetManager {

}

void updateModules() {
void updateModules(boolean recurse_submodules ) {

if( !localPath )
return // nothing to do
Expand All @@ -963,7 +963,11 @@ class AssetManager {

final init = git.submoduleInit()
final update = git.submoduleUpdate()
update.setStrategy(MergeStrategy.RECURSIVE)

if (recurse_submodules) {
update.setStrategy(MergeStrategy.RECURSIVE)
}

filter.each { String m -> init.addPath(m); update.addPath(m) }
// call submodule init
init.call()
Expand Down

0 comments on commit 8447dfd

Please sign in to comment.