Skip to content

Commit d0e79bf

Browse files
committed
Remove bogus SCM validation
As a follow-up to #7037, we decided to disable this bogus validation entirely since it doesn't add value compared to git's own output (it actually decreases the value since e.g. it omits the repository in question), it was emitted multiple times (probably still a bug for other validations that needs to be fixed) and it was unconditional, so e.g. it could cause SwiftPM to fail in cases where the branch/revision wouldn't be used anyway. I also opted to remove the existing test here since it doesn't seem to be very useful for us to test git itself. We will now always just use git and the user will get the same behavior as when they're using an invalid branch with git itself. rdar://117442643
1 parent c9bf5b3 commit d0e79bf

File tree

11 files changed

+0
-107
lines changed

11 files changed

+0
-107
lines changed

Fixtures/Miscellaneous/InvalidRefs/InvalidBranch/Package.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.

Fixtures/Miscellaneous/InvalidRefs/InvalidRevision/Package.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.

Sources/PackageLoading/ManifestLoader+Validation.swift

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,6 @@ public struct ManifestValidator {
217217

218218
func validateSourceControlDependency(_ dependency: PackageDependency.SourceControl) -> [Basics.Diagnostic] {
219219
var diagnostics = [Basics.Diagnostic]()
220-
221-
// validate source control ref
222-
switch dependency.requirement {
223-
case .branch(let name):
224-
// FIXME: removed this validation because it is applied unconditionally, rdar://117442643 tracks restoring it once we can do it right
225-
break
226-
case .revision(let revision):
227-
do {
228-
if try !self.sourceControlValidator.isValidRefFormat(revision) {
229-
diagnostics.append(.invalidSourceControlRevision(revision))
230-
}
231-
} catch {
232-
diagnostics.append(.invalidSourceControlRevision(revision, underlyingError: error))
233-
}
234-
default:
235-
break
236-
}
237220
// if a location is on file system, validate it is in fact a git repo
238221
// there is a case to be made to throw early (here) if the path does not exists
239222
// but many of our tests assume they can pass a non existent path
@@ -254,7 +237,6 @@ public struct ManifestValidator {
254237
}
255238

256239
public protocol ManifestSourceControlValidator {
257-
func isValidRefFormat(_ revision: String) throws -> Bool
258240
func isValidDirectory(_ path: AbsolutePath) throws -> Bool
259241
}
260242

@@ -319,14 +301,6 @@ extension Basics.Diagnostic {
319301
}
320302
}
321303

322-
static func invalidSourceControlBranchName(_ name: String, underlyingError: Error? = nil) -> Self {
323-
.error("invalid branch name: '\(name)'\(errorSuffix(underlyingError))")
324-
}
325-
326-
static func invalidSourceControlRevision(_ revision: String, underlyingError: Error? = nil) -> Self {
327-
.error("invalid revision: '\(revision)'\(errorSuffix(underlyingError))")
328-
}
329-
330304
static func invalidSourceControlDirectory(_ path: AbsolutePath, underlyingError: Error? = nil) -> Self {
331305
.error("cannot clone from local directory \(path)\nPlease git init or use \"path:\" for \(path)\(errorSuffix(underlyingError))")
332306
}

Sources/SPMTestSupport/InMemoryGitRepository.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,6 @@ public final class InMemoryGitRepositoryProvider: RepositoryProvider {
486486
return true
487487
}
488488

489-
public func isValidRefFormat(_ ref: String) throws -> Bool {
490-
return true
491-
}
492-
493489
public func cancel(deadline: DispatchTime) throws {
494490
// noop
495491
}

Sources/SourceControl/GitRepository.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,6 @@ public struct GitRepositoryProvider: RepositoryProvider, Cancellable {
210210
return result == ".git" || result == "." || result == directory.pathString
211211
}
212212

213-
/// Returns true if the git reference name is well formed.
214-
public func isValidRefFormat(_ ref: String) throws -> Bool {
215-
_ = try self.git.run(["check-ref-format", "--allow-onelevel", ref])
216-
return true
217-
}
218-
219213
public func copy(from sourcePath: Basics.AbsolutePath, to destinationPath: Basics.AbsolutePath) throws {
220214
try localFileSystem.copy(from: sourcePath, to: destinationPath)
221215
}

Sources/SourceControl/Repository.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ public protocol RepositoryProvider: Cancellable {
144144

145145
/// Returns true if the directory is valid git location.
146146
func isValidDirectory(_ directory: AbsolutePath) throws -> Bool
147-
148-
/// Returns true if the git reference name is well formed.
149-
func isValidRefFormat(_ ref: String) throws -> Bool
150147
}
151148

152149
/// Abstract repository operations.

Sources/SourceControl/RepositoryManager.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,6 @@ public class RepositoryManager: Cancellable {
426426
try self.provider.isValidDirectory(directory)
427427
}
428428

429-
/// Returns true if the git reference name is well formed.
430-
public func isValidRefFormat(_ ref: String) throws -> Bool {
431-
try self.provider.isValidRefFormat(ref)
432-
}
433-
434429
/// Reset the repository manager.
435430
///
436431
/// Note: This also removes the cloned repositories from the disk.

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -337,29 +337,6 @@ class MiscellaneousTestCase: XCTestCase {
337337
}
338338
}
339339

340-
func testInvalidRefsValidation() throws {
341-
try XCTSkipIf(true, "skipping since we disabled the validation, see rdar://117442643")
342-
343-
try fixture(name: "Miscellaneous/InvalidRefs", createGitRepo: false) { fixturePath in
344-
do {
345-
XCTAssertThrowsError(try SwiftPM.Build.execute(packagePath: fixturePath.appending("InvalidBranch"))) { error in
346-
guard case SwiftPMError.executionFailure(_, _, let stderr) = error else {
347-
return XCTFail("invalid error \(error)")
348-
}
349-
XCTAssert(stderr.contains("invalid branch name: "), "Didn't find expected output: \(stderr)")
350-
}
351-
}
352-
do {
353-
XCTAssertThrowsError(try SwiftPM.Build.execute(packagePath: fixturePath.appending("InvalidRevision"))) { error in
354-
guard case SwiftPMError.executionFailure(_, _, let stderr) = error else {
355-
return XCTFail("invalid error \(error)")
356-
}
357-
XCTAssert(stderr.contains("invalid revision: "), "Didn't find expected output: \(stderr)")
358-
}
359-
}
360-
}
361-
}
362-
363340
func testUnicode() throws {
364341
#if !os(Linux) && !os(Android) // TODO: - Linux has trouble with this and needs investigation.
365342
try fixture(name: "Miscellaneous/Unicode") { fixturePath in

Tests/PackageLoadingTests/PDLoadingTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ final class ManifestTestDelegate: ManifestLoaderDelegate {
190190
}
191191

192192
fileprivate struct NOOPManifestSourceControlValidator: ManifestSourceControlValidator {
193-
func isValidRefFormat(_ revision: String) throws -> Bool {
194-
true
195-
}
196-
197193
func isValidDirectory(_ path: AbsolutePath) throws -> Bool {
198194
true
199195
}

Tests/SourceControlTests/RepositoryManagerTests.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -561,10 +561,6 @@ class RepositoryManagerTests: XCTestCase {
561561
fatalError("should not be called")
562562
}
563563

564-
func isValidRefFormat(_ ref: String) throws -> Bool {
565-
fatalError("should not be called")
566-
}
567-
568564
func cancel(deadline: DispatchTime) throws {
569565
print("cancel")
570566
}
@@ -644,10 +640,6 @@ private class DummyRepository: Repository {
644640
fatalError("unexpected API call")
645641
}
646642

647-
func isValidRefFormat(_ ref: String) throws -> Bool {
648-
fatalError("unexpected API call")
649-
}
650-
651643
func fetch() throws {
652644
self.provider.increaseFetchCount()
653645
}
@@ -728,10 +720,6 @@ private class DummyRepositoryProvider: RepositoryProvider {
728720
return true
729721
}
730722

731-
func isValidRefFormat(_ ref: String) throws -> Bool {
732-
return true
733-
}
734-
735723
func cancel(deadline: DispatchTime) throws {
736724
// noop
737725
}

Tests/WorkspaceTests/SourceControlPackageContainerTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ private class MockRepositories: RepositoryProvider {
150150
return true
151151
}
152152

153-
func isValidRefFormat(_ ref: String) throws -> Bool {
154-
return true
155-
}
156-
157153
func cancel(deadline: DispatchTime) throws {
158154
// noop
159155
}

0 commit comments

Comments
 (0)