Skip to content

Commit 8e2691e

Browse files
Feedback - added back the validation on the matching path extension.
1 parent 51592d7 commit 8e2691e

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Sources/SourceControl/GitRepository.swift

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import Basics
1515
import Dispatch
1616
import class Foundation.NSLock
17+
import class Foundation.NSString
1718

1819
import struct PackageModel.CanonicalPackageURL
1920

@@ -211,6 +212,8 @@ public struct GitRepositoryProvider: RepositoryProvider, Cancellable {
211212
public func isValidDirectory(_ directory: Basics.AbsolutePath, for repository: RepositorySpecifier) throws -> Bool {
212213
let remoteURL = try self.git.run(["-C", directory.pathString, "config", "--get", "remote.origin.url"])
213214
return CanonicalPackageURL(remoteURL) == CanonicalPackageURL(repository.url)
215+
// NOTE: We require that the path extensions match (e.g. consistency for presence or absence of '.git')
216+
&& (remoteURL as NSString).pathExtension == (repository.url as NSString).pathExtension
214217
}
215218

216219
public func copy(from sourcePath: Basics.AbsolutePath, to destinationPath: Basics.AbsolutePath) throws {

Tests/SourceControlTests/GitRepositoryTests.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,10 @@ class GitRepositoryTests: XCTestCase {
798798

799799
let customRemoteWithoutPathExtension = (customRemote as NSString).deletingPathExtension
800800
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL(customRemote))))
801-
// We consider the directory valid even if the remote does not have the same path extension - in this case we expected '.git'.
802-
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL(customRemoteWithoutPathExtension))))
803-
// We consider the directory valid even if the remote does not have the same path extension - in this case we expected '.git'.
804-
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL((customRemote as NSString).deletingPathExtension + "/"))))
801+
// We consider the directory invalid if the remote does not have the same path extension - in this case we expected '.git'.
802+
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL(customRemoteWithoutPathExtension))))
803+
// We consider the directory invalid if the remote does not have the same path extension - in this case we expected '.git'.
804+
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL((customRemote as NSString).deletingPathExtension + "/"))))
805805

806806
// The following ensure that are actually checking the remote's origin.
807807
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(path: AbsolutePath(validating: "/"))))
@@ -846,12 +846,12 @@ class GitRepositoryTests: XCTestCase {
846846
let customRemotePathWithoutPathExtension = (customRemotePath as NSString).deletingPathExtension
847847
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(path: customRemote)))
848848
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL(customRemotePath))))
849-
// We consider the directory valid even if the remote does not have the same path extension - in this case we expected '.git'.
850-
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(path: try AbsolutePath(validating: customRemotePathWithoutPathExtension))))
851-
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL(customRemotePathWithoutPathExtension))))
852-
// We consider the directory valid even if the remote does not have the same path extension - in this case we expected '.git'.
853-
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(path: try AbsolutePath(validating: customRemotePathWithoutPathExtension + "/"))))
854-
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL((customRemotePath as NSString).deletingPathExtension + "/"))))
849+
// We consider the directory invalid if the remote does not have the same path extension - in this case we expected '.git'.
850+
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(path: try AbsolutePath(validating: customRemotePathWithoutPathExtension))))
851+
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL(customRemotePathWithoutPathExtension))))
852+
// We consider the directory invalid if the remote does not have the same path extension - in this case we expected '.git'.
853+
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(path: try AbsolutePath(validating: customRemotePathWithoutPathExtension + "/"))))
854+
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL((customRemotePath as NSString).deletingPathExtension + "/"))))
855855

856856
// The following ensure that are actually checking the remote's origin.
857857
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(path: AbsolutePath(validating: "/"))))
@@ -892,10 +892,10 @@ class GitRepositoryTests: XCTestCase {
892892
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir))
893893

894894
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL(customRemote))))
895-
// We consider the directory valid even if the remote does not have the same path extension - in this case we expected '.git'.
896-
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL("https://mycustomdomain/some-package"))))
897-
// We consider the directory valid even if the remote does not have the same path extension - in this case we expected '.git'.
898-
XCTAssertTrue(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL("https://mycustomdomain/some-package/"))))
895+
// We consider the directory invalid if the remote does not have the same path extension - in this case we expected '.git'.
896+
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL("https://mycustomdomain/some-package"))))
897+
// We consider the directory invalid if the remote does not have the same path extension - in this case we expected '.git'.
898+
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(url: SourceControlURL("https://mycustomdomain/some-package/"))))
899899

900900
// The following ensure that are actually checking the remote's origin.
901901
XCTAssertFalse(try repositoryManager.isValidDirectory(packageDir, for: RepositorySpecifier(path: AbsolutePath(validating: "/"))))

0 commit comments

Comments
 (0)