Skip to content

Commit 111a031

Browse files
committed
Address comments
1 parent aea38ca commit 111a031

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Sources/PackageModelSyntax/AddPackageDependency.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public enum AddPackageDependency {
4444
throw ManifestEditError.cannotFindPackage
4545
}
4646

47-
guard try checkExistingDependency(
47+
guard try !dependencyAlreadyAdded(
4848
dependency,
4949
in: packageCall
5050
) else {
@@ -62,17 +62,15 @@ public enum AddPackageDependency {
6262
)
6363
}
6464

65-
/// Check that the given package dependency doesn't already exist in the manifest.
66-
/// If the exact same dependency already exists, `false` is returned to indicate
67-
/// that no edits are needed. If a different dependency with the same id or url
68-
/// with different arguments exists, an error is thrown.
69-
private static func checkExistingDependency(
65+
/// Return `true` if the dependency already exists in the manifest, otherwise return `false`.
66+
/// Throws an error if a dependency already exists with the same id or url, but different arguments.
67+
private static func dependencyAlreadyAdded(
7068
_ dependency: MappablePackageDependency.Kind,
7169
in packageCall: FunctionCallExprSyntax
7270
) throws -> Bool {
7371
let dependencySyntax = dependency.asSyntax()
7472
guard let dependenctFnSyntax = dependencySyntax.as(FunctionCallExprSyntax.self) else {
75-
throw ManifestEditError.cannotFindPackage // TODO: Fix error
73+
throw ManifestEditError.cannotFindPackage
7674
}
7775

7876
guard let id = dependenctFnSyntax.arguments.first(where: {
@@ -92,20 +90,20 @@ public enum AddPackageDependency {
9290
$0.trimmedDescription == id.trimmedDescription
9391
}
9492
}
95-
return false
93+
return true
9694
}
9795

9896
if let existingArgument {
9997
let normalizedExistingArgument = existingArgument.detached.with(\.trailingComma, nil)
10098
// This exact dependency already exists, return false to indicate we should do nothing.
10199
if normalizedExistingArgument.trimmedDescription == dependencySyntax.trimmedDescription {
102-
return false
100+
return true
103101
}
104102
throw ManifestEditError.existingDependency(dependencyName: dependency.identifier)
105103
}
106104
}
107105
}
108-
return true
106+
return false
109107
}
110108

111109
/// Implementation of adding a package dependency to an existing call.

Tests/CommandsTests/PackageCommandTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase {
963963
try await executeAddURLDependencyAndAssert(
964964
packagePath: path,
965965
initialManifest: manifest,
966-
url: "https://github.com/swiftlang/swift-syntax.git",
966+
url: url,
967967
requirementArgs: ["--exact", "601.0.1"],
968968
expectedManifestString: expected
969969
)

0 commit comments

Comments
 (0)