Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix error on trying to install package with name only #181

Merged
merged 1 commit into from
Oct 23, 2020
Merged
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
16 changes: 9 additions & 7 deletions Sources/MintKit/Mint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ public class Mint {
@discardableResult
func resolvePackage(_ package: PackageReference) throws -> Bool {

// resolve version from MintFile
if package.version.isEmpty,
mintFilePath.exists,
let mintfile = try? Mintfile(path: mintFilePath) {
// set version to version from mintfile
if let mintFilePackage = mintfile.package(for: package.repo), !mintFilePackage.version.isEmpty {
// resolve repo and version from MintFile
if mintFilePath.exists,
let mintfile = try? Mintfile(path: mintFilePath),
let mintFilePackage = mintfile.package(for: package.repo) {
// set repo to repo from mintfile
package.repo = mintFilePackage.repo

if package.version.isEmpty, !mintFilePackage.version.isEmpty {
// set version to version from mintfile
package.version = mintFilePackage.version
package.repo = mintFilePackage.repo
if verbose {
output("Using \(package.repo) \(package.version) from Mintfile.")
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Fixtures/MintfileWithoutVersion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yonaskolb/SimplePackage
1 change: 1 addition & 0 deletions Tests/MintTests/Fixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ import PathKit
let mintFileFixture = Path(#file) + "../../Fixtures/Mintfile"
let simpleMintFileFixture = Path(#file) + "../../Fixtures/SimpleMintfile"
let complexMintFileFixture = Path(#file) + "../../Fixtures/ComplexMintfile"
let mintFileWithoutVersionFixture = Path(#file) + "../../Fixtures/MintfileWithoutVersion"
18 changes: 18 additions & 0 deletions Tests/MintTests/MintTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ class MintTests: XCTestCase {
try checkInstalledVersion(package: specificPackage, executable: testCommand)
}

func testMintFileWithoutVersionInstall() throws {
mint.mintFilePath = mintFileWithoutVersionFixture.absolute()

let specificPackage = PackageReference(repo: testRepoName)
try mint.install(package: specificPackage)
XCTAssertEqual(specificPackage.version, latestVersion)
try checkInstalledVersion(package: specificPackage, executable: testCommand)
}

func testMintFileWithoutVersionRun() throws {
mint.mintFilePath = mintFileWithoutVersionFixture.absolute()

let specificPackage = PackageReference(repo: testRepoName)
try mint.run(package: specificPackage)
XCTAssertEqual(specificPackage.version, latestVersion)
try checkInstalledVersion(package: specificPackage, executable: testCommand)
}

func testMintErrors() {

expectError(MintError.cloneError(PackageReference(repo: "http://invaliddomain.com/invalid", version: testVersion))) {
Expand Down