Skip to content

Commit

Permalink
Fix error on trying to install package with name only (#181)
Browse files Browse the repository at this point in the history
When Mintfile does not contain package versions, installing with simple
names such as `mint install xcodegen` fails with "package not found" error.
  • Loading branch information
kiyot authored Oct 23, 2020
1 parent 06f3914 commit b3b52da
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
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

0 comments on commit b3b52da

Please sign in to comment.