@@ -44,7 +44,7 @@ public enum AddPackageDependency {
44
44
throw ManifestEditError . cannotFindPackage
45
45
}
46
46
47
- guard try checkExistingDependency (
47
+ guard try ! dependencyAlreadyAdded (
48
48
dependency,
49
49
in: packageCall
50
50
) else {
@@ -62,17 +62,15 @@ public enum AddPackageDependency {
62
62
)
63
63
}
64
64
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(
70
68
_ dependency: MappablePackageDependency . Kind ,
71
69
in packageCall: FunctionCallExprSyntax
72
70
) throws -> Bool {
73
71
let dependencySyntax = dependency. asSyntax ( )
74
72
guard let dependenctFnSyntax = dependencySyntax. as ( FunctionCallExprSyntax . self) else {
75
- throw ManifestEditError . cannotFindPackage // TODO: Fix error
73
+ throw ManifestEditError . cannotFindPackage
76
74
}
77
75
78
76
guard let id = dependenctFnSyntax. arguments. first ( where: {
@@ -92,20 +90,20 @@ public enum AddPackageDependency {
92
90
$0. trimmedDescription == id. trimmedDescription
93
91
}
94
92
}
95
- return false
93
+ return true
96
94
}
97
95
98
96
if let existingArgument {
99
97
let normalizedExistingArgument = existingArgument. detached. with ( \. trailingComma, nil )
100
98
// This exact dependency already exists, return false to indicate we should do nothing.
101
99
if normalizedExistingArgument. trimmedDescription == dependencySyntax. trimmedDescription {
102
- return false
100
+ return true
103
101
}
104
102
throw ManifestEditError . existingDependency ( dependencyName: dependency. identifier)
105
103
}
106
104
}
107
105
}
108
- return true
106
+ return false
109
107
}
110
108
111
109
/// Implementation of adding a package dependency to an existing call.
0 commit comments