Skip to content

Commit 50b406c

Browse files
committed
Make sure that lock does not fail if non-dependecy in dev is dirty
- fixes #1007
1 parent d68b2cb commit 50b406c

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

src/nimble.nim

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,14 +1508,13 @@ proc updateSyncFile(dependentPkg: PackageInfo, options: Options) =
15081508
syncFile.save
15091509

15101510
proc validateDevModeDepsWorkingCopiesBeforeLock(
1511-
pkgInfo: PackageInfo, options: Options) =
1511+
pkgInfo: PackageInfo, options: Options): ValidationErrors =
15121512
## Validates that the develop mode dependencies states are suitable for
15131513
## locking. They must be under version control, their working copies must be
15141514
## in a clean state and their current VCS revision must be present on some of
15151515
## the configured remotes.
15161516

1517-
var errors: ValidationErrors
1518-
findValidationErrorsOfDevDepsWithLockFile(pkgInfo, options, errors)
1517+
findValidationErrorsOfDevDepsWithLockFile(pkgInfo, options, result)
15191518

15201519
# Those validation errors are not errors in the context of generating a lock
15211520
# file.
@@ -1526,12 +1525,9 @@ proc validateDevModeDepsWorkingCopiesBeforeLock(
15261525
}
15271526

15281527
# Remove not errors from the errors set.
1529-
for name, error in common.dup(errors):
1528+
for name, error in common.dup(result):
15301529
if error.kind in notAnErrorSet:
1531-
errors.del name
1532-
1533-
if errors.len > 0:
1534-
raise validationErrors(errors)
1530+
result.del name
15351531

15361532
proc mergeLockedDependencies*(pkgInfo: PackageInfo, newDeps: LockFileDeps,
15371533
options: Options): LockFileDeps =
@@ -1592,13 +1588,21 @@ proc lock(options: Options) =
15921588
let pkgInfo = getPkgInfo(currentDir, options)
15931589

15941590
let doesLockFileExist = displayLockOperationStart(currentDir)
1595-
validateDevModeDepsWorkingCopiesBeforeLock(pkgInfo, options)
1591+
var errors = validateDevModeDepsWorkingCopiesBeforeLock(pkgInfo, options)
15961592

15971593
let dependencies = pkgInfo.processFreeDependencies(options).map(
15981594
pkg => pkg.toFullInfo(options)).toSeq
15991595
pkgInfo.validateDevelopDependenciesVersionRanges(dependencies, options)
16001596
var dependencyGraph = buildDependencyGraph(dependencies, options)
16011597

1598+
# throw error only for dependencies that are part of the graph
1599+
for name, error in common.dup(errors):
1600+
if not dependencyGraph.contains(name):
1601+
errors.del name
1602+
1603+
if errors.len > 0:
1604+
raise validationErrors(errors)
1605+
16021606
if currentDir.lockFileExists:
16031607
# If we already have a lock file, merge its data with the newly generated
16041608
# one.
@@ -1856,7 +1860,7 @@ proc getPackageForAction(pkgInfo: PackageInfo, options: Options): PackageInfo =
18561860
## with the name specified in `options.package`. If `options.package` is empty
18571861
## or it matches the name of the `pkgInfo` then `pkgInfo` is returned. Raises
18581862
## a `NimbleError` if the package with the provided name is not found.
1859-
1863+
18601864
result = initPackageInfo()
18611865

18621866
if options.package.len == 0 or pkgInfo.basicInfo.name == options.package:

tests/tlockfile.nim

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ suite "lock file":
4646
`pkgName"PkgRepoPath"` {.used, inject.} = tempDir / `pkgName"PkgName"`
4747
`pkgName"PkgOriginRepoPath"`{.used, inject.} =
4848
originsDirPath / `pkgName"PkgName"`
49-
`pkgName"PkgRemoteName"` {.used, inject.} =
49+
`pkgName"PkgRemoteName"` {.used, inject.} =
5050
`pkgName"PkgName"` & "Remote"
5151
`pkgName"PkgRemotePath"` {.used, inject.} =
5252
additionalRemotesDirPath / `pkgName"PkgRemoteName"`
@@ -327,7 +327,7 @@ requires "nim >= 1.5.1"
327327
cd dep1PkgOriginRepoPath:
328328
createBranchAndSwitchToIt(branchName)
329329
addAdditionalFileToTheRepo("dep1.nim", additionalFileContent)
330-
330+
331331
cd dep2PkgOriginRepoPath:
332332
createBranchAndSwitchToIt(branchName)
333333
addAdditionalFileToTheRepo("dep2.nim", additionalFileContent)
@@ -370,7 +370,7 @@ requires "nim >= 1.5.1"
370370
# match those in the lock file.
371371
testLockedVcsRevisions(@[(dep1PkgName, dep1PkgRepoPath),
372372
(dep2PkgName, dep2PkgRepoPath)])
373-
373+
374374
test "can sync out of sync develop dependencies":
375375
outOfSyncDepsTest(""):
376376
testDepsSync()
@@ -408,8 +408,9 @@ requires "nim >= 1.5.1"
408408
@[dep1PkgName])
409409
initNewNimblePackage(dep1PkgOriginRepoPath, dep1PkgRepoPath)
410410
cd dep1PkgRepoPath:
411-
# Modify the Nimble file to make the working copy not clean.
412-
discard initNewNimbleFile(dep1PkgRepoPath, @[dep2PkgName])
411+
# Add a file to make the working copy not clean.
412+
writeFile("dirty", "dirty")
413+
addFiles("dirty")
413414
cd mainPkgRepoPath:
414415
writeDevelopFile(developFileName, @[], @[dep1PkgRepoPath])
415416
let (output, exitCode) = execNimbleYes("lock")
@@ -528,3 +529,25 @@ requires "nim >= 1.5.1"
528529
path: dep1PkgRepoPath)
529530
errorMessage = getValidationErrorMessage(dep1PkgName, error)
530531
check output.processOutput.inLines(errorMessage)
532+
533+
test "can lock with dirty non-deps in develop file":
534+
cleanUp()
535+
withPkgListFile:
536+
initNewNimblePackage(mainPkgOriginRepoPath, mainPkgRepoPath,
537+
@[dep1PkgName])
538+
initNewNimblePackage(dep1PkgOriginRepoPath, dep1PkgRepoPath)
539+
initNewNimblePackage(dep2PkgOriginRepoPath, dep2PkgRepoPath)
540+
541+
cd dep2PkgRepoPath:
542+
# make dep2 dirty
543+
writeFile("dirty", "dirty")
544+
addFiles("dirty")
545+
546+
547+
cd mainPkgRepoPath:
548+
# make main dirty
549+
writeFile("dirty", "dirty")
550+
addFiles("dirty")
551+
writeDevelopFile(developFileName, @[],
552+
@[dep2PkgRepoPath, mainPkgRepoPath, dep1PkgRepoPath])
553+
testLockFile(@[(dep1PkgName, dep1PkgRepoPath)], isNew = true)

0 commit comments

Comments
 (0)