diff --git a/Sources/GitKit/Git.swift b/Sources/GitKit/Git.swift index 04ea514..3567079 100644 --- a/Sources/GitKit/Git.swift +++ b/Sources/GitKit/Git.swift @@ -18,7 +18,7 @@ public final class Git: Shell { case status(short: Bool = false) case commit(message: String, Bool = false) case config(name: String, value: String) - case clone(url: String) + case clone(url: String , dirName: String? = nil) case checkout(branch: String, create: Bool = false) case log(numberOfCommits: Int? = nil, options: [String]? = nil, revisions: String? = nil) case push(remote: String? = nil, branch: String? = nil) @@ -57,8 +57,11 @@ public final class Git: Shell { if allowEmpty { params.append("--allow-empty") } - case .clone(let url): + case .clone(let url, let dirname): params = [Command.clone.rawValue, url] + if let dirName = dirname { + params.append(dirName) + } case .checkout(let branch, let create): params = [Command.checkout.rawValue] if create { diff --git a/Tests/GitKitTests/GitKitTests.swift b/Tests/GitKitTests/GitKitTests.swift index 203acc5..bcd2ddc 100644 --- a/Tests/GitKitTests/GitKitTests.swift +++ b/Tests/GitKitTests/GitKitTests.swift @@ -74,7 +74,7 @@ final class GitKitTests: XCTestCase { let git = Git(path: path) try git.run(.cmd(.initialize)) try git.run(.commit(message: expectation, true)) - let out = try git.run(.log(1)) + let out = try git.run(.log(numberOfCommits: 1)) try self.clean(path: path) XCTAssertTrue(out.hasSuffix(expectation), "Commit was not created.") } @@ -104,6 +104,25 @@ final class GitKitTests: XCTestCase { self.assert(type: "output", result: statusOutput, expected: expectation) } + func testCloneWithDirectory() throws { + let path = self.currentPath() + + let expectation = """ + On branch main + Your branch is up to date with 'origin/main'. + + nothing to commit, working tree clean + """ + + try self.clean(path: path) + let git = Git(path: path) + + try git.run(.clone(url: "https://github.com/binarybirds/shell-kit.git", dirName: "MyCustomDirectory")) + let statusOutput = try git.run("cd \(path)/MyCustomDirectory && git status") + try self.clean(path: path) + self.assert(type: "output", result: statusOutput, expected: expectation) + } + #if os(macOS) func testAsyncRun() throws { let path = self.currentPath()