Skip to content

add custom directory name parameter to clone command #3

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions Tests/GitKitTests/GitKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ final class GitKitTests: XCTestCase {
try self.clean(path: path)
self.assert(type: "output", result: statusOutput, expected: expectation)
}

func testCloneWithDirectory() throws {
let path = self.currentPath()

let expectation = """
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
"""

try self.clean(path: path)
let git = Git(path: path)

try git.run(.clone(url: "[email protected]:binarybirds/shell-kit", 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 {
Expand Down