Skip to content

Support for specifying a branch for a dependency. #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Get/Fetchable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import struct PackageDescription.Version

protocol Fetchable {
var version: Version { get }
var children: [(String, Range<Version>)] { get }
var children: [(String, String, Range<Version>)] { get }

/**
This should be a separate protocol. But Swift 2 was not happy
Expand Down
12 changes: 6 additions & 6 deletions Sources/Get/Fetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ protocol Fetcher {
associatedtype T: Fetchable

func find(url url: String) throws -> Fetchable?
func fetch(url url: String) throws -> Fetchable
func fetch(url url: String, branch: String) throws -> Fetchable
func finalize(fetchable: Fetchable) throws -> T

func recursivelyFetch(urls: [(String, Range<Version>)]) throws -> [T]
func recursivelyFetch(urls: [(String, String, Range<Version>)]) throws -> [T]
}

extension Fetcher {
Expand All @@ -30,13 +30,13 @@ extension Fetcher {

This is our standard implementation that we override when testing.
*/
func recursivelyFetch(urls: [(String, Range<Version>)]) throws -> [T] {
func recursivelyFetch(urls: [(String, String, Range<Version>)]) throws -> [T] {

var graph = [String: (Fetchable, Range<Version>)]()

func recurse(urls: [(String, Range<Version>)]) throws -> [String] {
func recurse(urls: [(String, String, Range<Version>)]) throws -> [String] {

return try urls.flatMap { url, specifiedVersionRange -> [String] in
return try urls.flatMap { url, branch, specifiedVersionRange -> [String] in

func adjust(pkg: Fetchable, _ versionRange: Range<Version>) throws {
guard let v = pkg.constrain(to: versionRange) else {
Expand Down Expand Up @@ -89,7 +89,7 @@ extension Fetcher {

// clone the package

let clone = try self.fetch(url: url)
let clone = try self.fetch(url: url, branch: branch)
try adjust(clone, specifiedVersionRange)
graph[url] = (clone, specifiedVersionRange)
return try recurse(clone.children) + [url]
Expand Down
7 changes: 5 additions & 2 deletions Sources/Get/Git.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import enum POSIX.Error
import Utility

extension Git {
class func clone(url: String, to dstdir: String) throws -> Repo {
class func clone(url: String, branch: String, to dstdir: String) throws -> Repo {
// canonicalize URL
var url = url
if URL.scheme(url) == nil {
Expand All @@ -34,7 +34,10 @@ extension Git {
try system(Git.tool, "clone",
"--recursive", // get submodules too so that developers can use these if they so choose
"--depth", "10",
url, dstdir, environment: environment, message: "Cloning \(url)")
"--branch", branch, "--single-branch",
url, dstdir,
environment: environment,
message: "Cloning \(url)" + (branch == "master" ? "" : " \(branch)"))
} catch POSIX.Error.ExitStatus {
// Git 2.0 or higher is required
if Git.majorVersionNumber < 2 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Get/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ extension Package {
}

extension Package: Fetchable {
var children: [(String, Range<Version>)] {
return manifest.package.dependencies.map{ ($0.url, $0.versionRange) }
var children: [(String, String, Range<Version>)] {
return manifest.package.dependencies.map{ ($0.url, $0.branch, $0.versionRange) }
}

private var versionString: String.CharacterView {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Get/PackagesDirectory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ extension PackagesDirectory: Fetcher {
return nil
}

func fetch(url url: String) throws -> Fetchable {
func fetch(url url: String, branch: String) throws -> Fetchable {
let dstdir = Path.join(prefix, Package.nameForURL(url))
if let repo = Git.Repo(path: dstdir) where repo.origin == url {
//TODO need to canonicalize the URL need URL struct
return try RawClone(path: dstdir, manifestParser: manifestParser)
}

// fetch as well, clone does not fetch all tags, only tags on the master branch
try Git.clone(url, to: dstdir).fetch()
try Git.clone(url, branch: branch, to: dstdir).fetch()

return try RawClone(path: dstdir, manifestParser: manifestParser)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Get/RawClone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class RawClone: Fetchable {
}.last
}

var children: [(String, Range<Version>)] {
var children: [(String, String, Range<Version>)] {
guard manifest != nil else {
// manifest may not exist, if so the package is BAD,
// still: we should not crash. Build failure will occur
Expand Down
4 changes: 2 additions & 2 deletions Sources/Get/get().swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public func get(manifest: Manifest, manifestParser: (path: String, url: String)
import PackageDescription

extension Manifest {
var dependencies: [(String, Range<Version>)] {
return package.dependencies.map{ ($0.url, $0.versionRange) }
var dependencies: [(String, String, Range<Version>)] {
return package.dependencies.map{ ($0.url, $0.branch, $0.versionRange) }
}
}
9 changes: 5 additions & 4 deletions Sources/ManifestParser/fromTOML().swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ extension PackageDescription.Package {

extension PackageDescription.Package.Dependency {
public static func fromTOML(item: TOMLItem, baseURL: String?) -> PackageDescription.Package.Dependency {
guard case .Array(let array) = item where array.items.count == 3 else {
guard case .Array(let array) = item where array.items.count == 4 else {
fatalError("Unexpected TOMLItem")
}
guard case .String(let url) = array.items[0],
case .String(let vv1) = array.items[1],
case .String(let vv2) = array.items[2],
case .String(let branch) = array.items[1],
case .String(let vv1) = array.items[2],
case .String(let vv2) = array.items[3],
let v1 = Version(vv1), v2 = Version(vv2)
else {
fatalError("Unexpected TOMLItem")
Expand All @@ -81,7 +82,7 @@ extension PackageDescription.Package.Dependency {
}
}

return PackageDescription.Package.Dependency.Package(url: fixURL(), versions: v1..<v2)
return PackageDescription.Package.Dependency.Package(url: fixURL(), branch: branch, versions: v1..<v2)
}
}

Expand Down
22 changes: 12 additions & 10 deletions Sources/PackageDescription/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ public final class Package {
public class Dependency {
public let versionRange: Range<Version>
public let url: String
public let branch: String

init(_ url: String, _ versionRange: Range<Version>) {
init(_ url: String, _ branch: String, _ versionRange: Range<Version>) {
self.url = url
self.branch = branch
self.versionRange = versionRange
}

public class func Package(url url: String, versions: Range<Version>) -> Dependency {
return Dependency(url, versions)
public class func Package(url url: String, branch: String = "master", versions: Range<Version>) -> Dependency {
return Dependency(url, branch, versions)
}
public class func Package(url url: String, majorVersion: Int) -> Dependency {
return Dependency(url, Version(majorVersion, 0, 0)..<Version(majorVersion, .max, .max))
public class func Package(url url: String, branch: String = "master", majorVersion: Int) -> Dependency {
return Dependency(url, branch, Version(majorVersion, 0, 0)..<Version(majorVersion, .max, .max))
}
public class func Package(url url: String, majorVersion: Int, minor: Int) -> Dependency {
return Dependency(url, Version(majorVersion, minor, 0)..<Version(majorVersion, minor, .max))
public class func Package(url url: String, branch: String = "master", majorVersion: Int, minor: Int) -> Dependency {
return Dependency(url, branch, Version(majorVersion, minor, 0)..<Version(majorVersion, minor, .max))
}
public class func Package(url url: String, _ version: Version) -> Dependency {
return Dependency(url, version...version)
public class func Package(url url: String, branch: String = "master", _ version: Version) -> Dependency {
return Dependency(url, branch, version...version)
}
}

Expand Down Expand Up @@ -80,7 +82,7 @@ public final class Package {

extension Package.Dependency: TOMLConvertible {
public func toTOML() -> String {
return "[\"\(url)\", \"\(versionRange.startIndex)\", \"\(versionRange.endIndex)\"],"
return "[\"\(url)\", \"\(branch)\", \"\(versionRange.startIndex)\", \"\(versionRange.endIndex)\"],"
}
}

Expand Down
Loading