From 8447dfdd8edb9eddb83d61691ff1d622678dc841 Mon Sep 17 00:00:00 2001 From: Akira Sekiguchi Date: Tue, 9 Jun 2020 20:49:27 +0900 Subject: [PATCH] Add recursive options to nextflow run/clone/pull commands --- .../src/main/groovy/nextflow/cli/CmdClone.groovy | 5 ++++- .../src/main/groovy/nextflow/cli/CmdPull.groovy | 6 ++++-- .../src/main/groovy/nextflow/cli/CmdRun.groovy | 7 +++++-- .../main/groovy/nextflow/scm/AssetManager.groovy | 16 ++++++++++------ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/modules/nextflow/src/main/groovy/nextflow/cli/CmdClone.groovy b/modules/nextflow/src/main/groovy/nextflow/cli/CmdClone.groovy index bbab25940e..4babf3fbf3 100644 --- a/modules/nextflow/src/main/groovy/nextflow/cli/CmdClone.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/cli/CmdClone.groovy @@ -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 } @@ -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" } diff --git a/modules/nextflow/src/main/groovy/nextflow/cli/CmdPull.groovy b/modules/nextflow/src/main/groovy/nextflow/cli/CmdPull.groovy index 5ac9d0063c..23569fa3bc 100644 --- a/modules/nextflow/src/main/groovy/nextflow/cli/CmdPull.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/cli/CmdPull.groovy @@ -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 @@ -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" diff --git a/modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy b/modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy index 92860414a1..e5412ba3d3 100644 --- a/modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy @@ -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 */ @@ -336,7 +339,7 @@ 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 @@ -344,7 +347,7 @@ class CmdRun extends CmdBase implements HubOptions { // 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 ) diff --git a/modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy b/modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy index 34d2e8776e..da94766cb1 100644 --- a/modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/scm/AssetManager.groovy @@ -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 /* @@ -591,7 +591,7 @@ class AssetManager { clone .setURI(cloneURL) .setDirectory(localPath) - .setCloneSubmodules(true) + .setCloneSubmodules(recurse_submodules) .call() // return status message @@ -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() @@ -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)) @@ -939,7 +939,7 @@ class AssetManager { } - void updateModules() { + void updateModules(boolean recurse_submodules ) { if( !localPath ) return // nothing to do @@ -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()