From 7c74e4a06ee4139b3a9e4aa168d5a18bfa6a2930 Mon Sep 17 00:00:00 2001 From: Ivan Bobev Date: Wed, 4 Aug 2021 14:51:29 +0300 Subject: [PATCH] Enhance `develop --with-dependencies` Make `develop --with-dependencies` to skip already existing directories when cloning the repositories. This is useful when a second `develop --with-dependencies` is executed for another package and some of the dependencies are the same as in the first run. In that case, we don't want the entire command to fail because some package directories already exist. Related to nim-lang/nimble#127 --- src/nimble.nim | 25 +++++++++++++++++++++++-- src/nimblepkg/displaymessages.nim | 4 ++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index bc5ce811..bff53c2c 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -537,7 +537,19 @@ proc downloadDependency(name: string, dep: LockFileDep, options: Options): getDevelopDownloadDir(url, subdir, options) else: "" if dirExists(downloadPath): - raiseCannotCloneInExistingDirException(downloadPath) + if options.developWithDependencies: + displayWarning(skipDownloadingInAlreadyExistingDirectoryMsg( + downloadPath, name)) + result = DownloadInfo( + name: name, + dependency: dep, + url: url, + version: version, + downloadDir: downloadPath, + vcsRevision: dep.vcsRevision.newClone) + return + else: + raiseCannotCloneInExistingDirException(downloadPath) let (downloadDir, _, vcsRevision) = await downloadPkg( url, version, dep.downloadMethod, subdir, options, downloadPath, @@ -1213,7 +1225,16 @@ proc installDevelopPackage(pkgTup: PkgTuple, options: var Options): let downloadDir = getDevelopDownloadDir(url, subdir, options) if dirExists(downloadDir): - raiseCannotCloneInExistingDirException(downloadDir) + if options.developWithDependencies: + displayWarning(skipDownloadingInAlreadyExistingDirectoryMsg( + downloadDir, pkgTup.name)) + let pkgInfo = getPkgInfo(downloadDir, options) + developFromDir(pkgInfo, options) + options.action.devActions.add( + (datAdd, pkgInfo.getNimbleFileDir.normalizedPath)) + return pkgInfo + else: + raiseCannotCloneInExistingDirException(downloadDir) # Download the HEAD and make sure the full history is downloaded. let ver = diff --git a/src/nimblepkg/displaymessages.nim b/src/nimblepkg/displaymessages.nim index 1068425b..046b5321 100644 --- a/src/nimblepkg/displaymessages.nim +++ b/src/nimblepkg/displaymessages.nim @@ -153,3 +153,7 @@ proc pkgAlreadyExistsInTheCacheMsg*(pkgInfo: PackageInfo): string = pkgInfo.basicInfo.name, $pkgInfo.basicInfo.version, $pkgInfo.basicInfo.checksum) + +proc skipDownloadingInAlreadyExistingDirectoryMsg*(dir, name: string): string = + &"The download directory \"{dir}\" already exists.\n" & + &"Skipping the download of \"{name}\"."