Skip to content

Commit 9ffc46b

Browse files
authored
Install submodules and adds ignoreSubmodules flag (#1364)
* Install submodules and adds `ignoreSubmodules` flag * Update download.nim
1 parent bf28d04 commit 9ffc46b

File tree

5 files changed

+142
-125
lines changed

5 files changed

+142
-125
lines changed

src/nimblepkg/download.nim

+21-17
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,40 @@ proc updateSubmodules(dir: string) =
1919
discard tryDoCmdEx(
2020
&"git -C {dir} submodule update --init --recursive --depth 1")
2121

22-
proc doCheckout*(meth: DownloadMethod, downloadDir, branch: string) =
22+
proc doCheckout*(meth: DownloadMethod, downloadDir, branch: string, options: Options) =
2323
case meth
2424
of DownloadMethod.git:
2525
# Force is used here because local changes may appear straight after a clone
2626
# has happened. Like in the case of git on Windows where it messes up the
2727
# damn line endings.
2828
discard tryDoCmdEx(&"git -C {downloadDir} checkout --force {branch}")
29-
downloadDir.updateSubmodules
29+
if not options.ignoreSubmodules:
30+
downloadDir.updateSubmodules
3031
of DownloadMethod.hg:
3132
discard tryDoCmdEx(&"hg --cwd {downloadDir} checkout {branch}")
3233

3334
proc doClone(meth: DownloadMethod, url, downloadDir: string, branch = "",
34-
onlyTip = true) =
35+
onlyTip = true, options: Options) =
3536
case meth
3637
of DownloadMethod.git:
3738
let
39+
submoduleFlag = if not options.ignoreSubmodules: " --recurse-submodules" else: ""
3840
depthArg = if onlyTip: "--depth 1" else: ""
3941
branchArg = if branch == "": "" else: &"-b {branch}"
4042
discard tryDoCmdEx(
41-
"git clone --config core.autocrlf=false --config core.eol=lf --recursive " &
42-
&"{depthArg} {branchArg} {url} {downloadDir}")
43+
"git clone --config core.autocrlf=false --config core.eol=lf " &
44+
&"{submoduleFlag} {depthArg} {branchArg} {url} {downloadDir}")
4345
of DownloadMethod.hg:
4446
let
4547
tipArg = if onlyTip: "-r tip " else: ""
4648
branchArg = if branch == "": "" else: &"-b {branch}"
4749
discard tryDoCmdEx(&"hg clone {tipArg} {branchArg} {url} {downloadDir}")
4850

49-
proc gitFetchTags*(repoDir: string, downloadMethod: DownloadMethod) =
51+
proc gitFetchTags*(repoDir: string, downloadMethod: DownloadMethod, options: Options) =
5052
case downloadMethod:
5153
of DownloadMethod.git:
52-
tryDoCmdEx(&"git -C {repoDir} fetch --tags")
54+
let submoduleFlag = if not options.ignoreSubmodules: " --recurse-submodules" else: ""
55+
tryDoCmdEx(&"git -C {repoDir} fetch --tags" & submoduleFlag)
5356
of DownloadMethod.hg:
5457
assert false, "hg not supported"
5558

@@ -144,7 +147,7 @@ proc getUrlData*(url: string): (string, Table[string, string]) =
144147

145148
proc cloneSpecificRevision(downloadMethod: DownloadMethod,
146149
url, downloadDir: string,
147-
vcsRevision: Sha1Hash) =
150+
vcsRevision: Sha1Hash, options: Options) =
148151
assert vcsRevision != notSetSha1Hash
149152

150153
display("Cloning", "revision: " & $vcsRevision, priority = MediumPriority)
@@ -158,7 +161,8 @@ proc cloneSpecificRevision(downloadMethod: DownloadMethod,
158161
discard tryDoCmdEx(
159162
&"git -C {downloadDir} fetch --depth 1 origin {vcsRevision}")
160163
discard tryDoCmdEx(&"git -C {downloadDir} reset --hard FETCH_HEAD")
161-
downloadDir.updateSubmodules
164+
if not options.ignoreSubmodules:
165+
downloadDir.updateSubmodules
162166
of DownloadMethod.hg:
163167
discard tryDoCmdEx(&"hg clone {url} -r {vcsRevision}")
164168

@@ -372,7 +376,7 @@ proc doDownload(url, downloadDir: string, verRange: VersionRange,
372376
if downloadTarball(url, options):
373377
discard doDownloadTarball(url, downloadDir, $vcsRevision, false)
374378
else:
375-
cloneSpecificRevision(downMethod, url, downloadDir, vcsRevision)
379+
cloneSpecificRevision(downMethod, url, downloadDir, vcsRevision, options)
376380
result.vcsRevision = vcsRevision
377381
elif verRange.kind == verSpecial:
378382
# We want a specific commit/branch/tag here.
@@ -382,7 +386,7 @@ proc doDownload(url, downloadDir: string, verRange: VersionRange,
382386
result.vcsRevision = doDownloadTarball(url, downloadDir, "HEAD", true)
383387
else:
384388
doClone(downMethod, url, downloadDir,
385-
onlyTip = not options.forceFullClone)
389+
onlyTip = not options.forceFullClone, options = options)
386390
else:
387391
assert ($verRange.spe)[0] == '#',
388392
"The special version must start with '#'."
@@ -392,10 +396,10 @@ proc doDownload(url, downloadDir: string, verRange: VersionRange,
392396
url, downloadDir, specialVersion, true)
393397
else:
394398
# Grab the full repo.
395-
doClone(downMethod, url, downloadDir, onlyTip = false)
399+
doClone(downMethod, url, downloadDir, onlyTip = false, options = options)
396400
# Then perform a checkout operation to get the specified branch/commit.
397401
# `spe` starts with '#', trim it.
398-
doCheckout(downMethod, downloadDir, specialVersion)
402+
doCheckout(downMethod, downloadDir, specialVersion, options = options)
399403
result.version = verRange.spe
400404
else:
401405
case downMethod
@@ -415,26 +419,26 @@ proc doDownload(url, downloadDir: string, verRange: VersionRange,
415419
display("Cloning", "latest tagged version: " & latest.tag,
416420
priority = MediumPriority)
417421
doClone(downMethod, url, downloadDir, latest.tag,
418-
onlyTip = not options.forceFullClone)
422+
onlyTip = not options.forceFullClone, options = options)
419423
else:
420424
display("Warning:", "The package has no tagged releases, downloading HEAD instead.", Warning,
421425
priority = HighPriority)
422426
if downloadTarball(url, options):
423427
result.vcsRevision = doDownloadTarball(url, downloadDir, "HEAD", true)
424428
else:
425429
# If no commits have been tagged on the repo we just clone HEAD.
426-
doClone(downMethod, url, downloadDir, onlyTip = not options.forceFullClone) # Grab HEAD.
430+
doClone(downMethod, url, downloadDir, onlyTip = not options.forceFullClone, options = options) # Grab HEAD.
427431
of DownloadMethod.hg:
428432
doClone(downMethod, url, downloadDir,
429-
onlyTip = not options.forceFullClone)
433+
onlyTip = not options.forceFullClone, options = options)
430434
result.version = getHeadName(downMethod)
431435
let versions = getTagsList(downloadDir, downMethod).getVersionList()
432436

433437
if versions.len > 0:
434438
getLatestByTag:
435439
display("Switching", "to latest tagged version: " & latest.tag,
436440
priority = MediumPriority)
437-
doCheckout(downMethod, downloadDir, latest.tag)
441+
doCheckout(downMethod, downloadDir, latest.tag, options = options)
438442
else:
439443
display("Warning:", "The package has no tagged releases, downloading HEAD instead.", Warning,
440444
priority = HighPriority)

src/nimblepkg/nimblesat.nim

+3-3
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ proc getTaggedVersions*(repoDir, pkgName: string, options: Options): Option[Tagg
524524
displayWarning(&"Error reading tagged versions: {e.msg}", HighPriority)
525525
return none(TaggedPackageVersions)
526526
else:
527-
none(TaggedPackageVersions)
527+
return none(TaggedPackageVersions)
528528

529529
proc saveTaggedVersions*(repoDir, pkgName: string, taggedVersions: TaggedPackageVersions, options: Options) =
530530
var file: string
@@ -552,7 +552,7 @@ proc getPackageMinimalVersionsFromRepo*(repoDir: string, pkg: PkgTuple, version:
552552
copyDir(repoDir, tempDir)
553553
var tags = initOrderedTable[Version, string]()
554554
try:
555-
gitFetchTags(tempDir, downloadMethod)
555+
gitFetchTags(tempDir, downloadMethod, options)
556556
tags = getTagsList(tempDir, downloadMethod).getVersionList()
557557
except CatchableError as e:
558558
displayWarning(&"Error fetching tags for {name}: {e.msg}", HighPriority)
@@ -576,7 +576,7 @@ proc getPackageMinimalVersionsFromRepo*(repoDir: string, pkg: PkgTuple, version:
576576
displayInfo(&"Ignoring {name}:{tagVersion} because out of range {pkg[1]}")
577577
break
578578

579-
doCheckout(downloadMethod, tempDir, tag)
579+
doCheckout(downloadMethod, tempDir, tag, options)
580580
let nimbleFile = findNimbleFile(tempDir, true, options)
581581
if options.useDeclarativeParser:
582582
result.addUnique getMinimalInfo(nimbleFile, name, options)

src/nimblepkg/options.nim

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type
6666
maxTaggedVersions*: int # Maximum number of tags to check for a package when discovering versions in a local repo
6767
useDeclarativeParser*: bool # Whether to use the declarative parser for parsing nimble files (only when solver is SAT)
6868
features*: seq[string] # Features to be activated. Only used when using the declarative parser
69+
ignoreSubmodules*: bool # Whether to ignore submodules when cloning a repository
6970

7071
ActionType* = enum
7172
actionNil, actionRefresh, actionInit, actionDump, actionPublish, actionUpgrade
@@ -280,6 +281,7 @@ Nimble Options:
280281
--maximumTaggedVersions Maximum number of tags to check for a package when discovering versions for the SAT solver. 0 means all.
281282
--parser:declarative|nimvm Use the declarative parser or the nimvm parser (default).
282283
--features Activate features. Only used when using the declarative parser.
284+
--ignoreSubmodules Ignore submodules when cloning a repository.
283285
For more information read the GitHub readme:
284286
https://github.com/nim-lang/nimble#readme
285287
"""
@@ -684,6 +686,8 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
684686
raise nimbleError(&"{val} is not a valid value")
685687
of "features":
686688
result.features = val.split(";").mapIt(it.strip)
689+
of "ignoresubmodules":
690+
result.ignoreSubmodules = true
687691
else: isGlobalFlag = false
688692

689693
var wasFlagHandled = true

tests/tissues.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,5 @@ suite "issues":
413413
let message = "compiling nim package using " & nimBin
414414
check exitCode == QuitSuccess
415415
check output.contains(message)
416-
removeDir("testDir-1251")
416+
removeDir("testDir-1251")
417+

0 commit comments

Comments
 (0)