Skip to content

Commit

Permalink
[Cartfile] Reject git or ssh protocol as a github origin as it …
Browse files Browse the repository at this point in the history
…does not make sense
  • Loading branch information
ikesyo committed Sep 7, 2018
1 parent 4c58c72 commit a4d61d6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Carthage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
BF7A1A0B1E3A7AE9008CBCC5 /* BinaryProject.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF7A1A091E3A7188008CBCC5 /* BinaryProject.swift */; };
BFFA7A631E3AAFD200CB95A7 /* BinaryProjectSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFFA7A621E3AAFD200CB95A7 /* BinaryProjectSpec.swift */; };
CD09E28B1F0E3FFB00A0378A /* FakeSwift.framework in Resources */ = {isa = PBXBuildFile; fileRef = CD09E2881F0E3F1400A0378A /* FakeSwift.framework */; };
CD1491CD2142CF6D000C9CE1 /* GitHubSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1491CC2142CF6D000C9CE1 /* GitHubSpec.swift */; };
CD28C99D1E11846200322AF7 /* ProductType.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD28C99C1E11846200322AF7 /* ProductType.swift */; };
CD3E530B1DE33095002C135C /* Availability.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3E530A1DE33095002C135C /* Availability.swift */; };
CD43D9DA1F41640E00CD60F6 /* CarthageKitVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD43D9D91F41640E00CD60F6 /* CarthageKitVersion.swift */; };
Expand Down Expand Up @@ -234,6 +235,7 @@
BF7A1A091E3A7188008CBCC5 /* BinaryProject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BinaryProject.swift; sourceTree = "<group>"; };
BFFA7A621E3AAFD200CB95A7 /* BinaryProjectSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BinaryProjectSpec.swift; sourceTree = "<group>"; };
CD09E2881F0E3F1400A0378A /* FakeSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = FakeSwift.framework; sourceTree = "<group>"; };
CD1491CC2142CF6D000C9CE1 /* GitHubSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GitHubSpec.swift; sourceTree = "<group>"; };
CD28C99C1E11846200322AF7 /* ProductType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductType.swift; sourceTree = "<group>"; };
CD3E530A1DE33095002C135C /* Availability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Availability.swift; sourceTree = "<group>"; };
CD43D9D91F41640E00CD60F6 /* CarthageKitVersion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CarthageKitVersion.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -593,6 +595,7 @@
D0D121DF19E8999E005E4BAA /* CartfileSpec.swift */,
BF3199BF1E32E078007DC0D1 /* DependencySpec.swift */,
89A8F1771C24AB3C00C0E75A /* FrameworkExtensionsSpec.swift */,
CD1491CC2142CF6D000C9CE1 /* GitHubSpec.swift */,
CDA0B6C91C468E67006C499C /* GitURLSpec.swift */,
549B47AF1A4F17FF002498C7 /* ProjectSpec.swift */,
0FDFEA7D2055D638008862E3 /* ProxyTests.swift */,
Expand Down Expand Up @@ -920,6 +923,7 @@
D0DB09A419EA354200234B16 /* XcodeSpec.swift in Sources */,
0FDFEA7E2055D638008862E3 /* ProxyTests.swift in Sources */,
3A0472F61C7836EA00097EC7 /* AlgorithmsSpec.swift in Sources */,
CD1491CD2142CF6D000C9CE1 /* GitHubSpec.swift in Sources */,
BFFA7A631E3AAFD200CB95A7 /* BinaryProjectSpec.swift in Sources */,
D0C6E5741A57040B00A5E3E7 /* ArchiveSpec.swift in Sources */,
549B47B11A4F1A34002498C7 /* ProjectSpec.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Documentation/Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ github "ReactiveCocoa/ReactiveCocoa" # GitHub.com
github "https://enterprise.local/ghe/desktop/git-error-translations" # GitHub Enterprise
```

`github` origin is for specifying by `owner/repo` form or using prebuilt binary download feature through its web API, so using `git` or `ssh` protocol for `github` origin does not make sense and will be an error.

##### Git repositories

Other Git repositories are specified with the `git` keyword:
Expand Down
4 changes: 4 additions & 0 deletions Source/CarthageKit/GitHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ extension Repository {
// Hostname-based → GitHub Enterprise
guard
let url = URL(string: identifier),
let scheme = url.scheme,
// Reject `git` or `ssh` protocol as a `github` origin as it does not make sense.
// See https://github.com/Carthage/Carthage/issues/2379.
(scheme == "http" || scheme == "https"),
let host = url.host,
case var pathComponents = url.pathComponents.filter({ $0 != "/" }),
pathComponents.count >= 2,
Expand Down
36 changes: 36 additions & 0 deletions Tests/CarthageKitTests/GitHubSpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Foundation
import Nimble
import Quick

import Tentacle
@testable import CarthageKit

class GitHubSpec: QuickSpec {
override func spec() {
describe("Repository.fromIdentifier") {
it("should parse owner/name form") {
let identifier = "ReactiveCocoa/ReactiveSwift"
let result = Repository.fromIdentifier(identifier)
expect(result.value?.0) == Server.dotCom
expect(result.value?.1) == Repository(owner: "ReactiveCocoa", name: "ReactiveSwift")
expect(result.error).to(beNil())
}

it("should reject git protocol") {
let identifier = "git://git@some_host/some_owner/some_repo.git"
let expected = ScannableError(message: "invalid GitHub repository identifier \"\(identifier)\"")
let result = Repository.fromIdentifier(identifier)
expect(result.value).to(beNil())
expect(result.error) == expected
}

it("should reject ssh protocol") {
let identifier = "ssh://git@some_host/some_owner/some_repo.git"
let expected = ScannableError(message: "invalid GitHub repository identifier \"\(identifier)\"")
let result = Repository.fromIdentifier(identifier)
expect(result.value).to(beNil())
expect(result.error) == expected
}
}
}
}

0 comments on commit a4d61d6

Please sign in to comment.