Skip to content
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
7 changes: 5 additions & 2 deletions Sources/GitKit/Git.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 20 additions & 1 deletion Tests/GitKitTests/GitKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down Expand Up @@ -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()
Expand Down