Skip to content

Commit 533ad19

Browse files
author
Andrew McKnight
committed
add custom directory name parameter to clone command
1 parent 9186482 commit 533ad19

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Sources/GitKit/Git.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public final class Git: Shell {
1717
case addAll
1818
case commit(message: String, Bool = false)
1919
case config(name: String, value: String)
20-
case clone(url: String)
20+
case clone(url: String, dirName: String? = nil)
2121
case checkout(branch: String)
2222
case log(Int? = nil)
2323
case push(remote: String? = nil, branch: String? = nil)
@@ -48,8 +48,11 @@ public final class Git: Shell {
4848
if allowEmpty {
4949
params.append("--allow-empty")
5050
}
51-
case .clone(let url):
51+
case .clone(let url, let dirname):
5252
params = [Command.clone.rawValue, url]
53+
if let dirName = dirname {
54+
params.append(dirName)
55+
}
5356
case .checkout(let branch):
5457
params = [Command.checkout.rawValue, branch]
5558
case .log(let n):

Tests/GitKitTests/GitKitTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@ final class GitKitTests: XCTestCase {
103103
try self.clean(path: path)
104104
self.assert(type: "output", result: statusOutput, expected: expectation)
105105
}
106+
107+
func testCloneWithDirectory() throws {
108+
let path = self.currentPath()
109+
110+
let expectation = """
111+
On branch master
112+
Your branch is up to date with 'origin/master'.
113+
114+
nothing to commit, working tree clean
115+
"""
116+
117+
try self.clean(path: path)
118+
let git = Git(path: path)
119+
120+
try git.run(.clone(url: "[email protected]:binarybirds/shell-kit", dirName: "MyCustomDirectory"))
121+
let statusOutput = try git.run("cd \(path)/MyCustomDirectory && git status")
122+
try self.clean(path: path)
123+
self.assert(type: "output", result: statusOutput, expected: expectation)
124+
}
106125

107126
#if os(macOS)
108127
func testAsyncRun() throws {

0 commit comments

Comments
 (0)