From ccded26a12efc6acc52b16130ffe5f858867b27d Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sun, 9 Feb 2025 15:13:24 -0900 Subject: [PATCH 1/3] add custom directory name parameter to clone command --- Sources/GitKit/Git.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 { From 2ec9e0bda4daf97365024648691661d249b14cfa Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:24:28 -0800 Subject: [PATCH 2/3] moving new test method to correct branch --- Tests/GitKitTests/GitKitTests.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Tests/GitKitTests/GitKitTests.swift b/Tests/GitKitTests/GitKitTests.swift index 203acc5..40f5a85 100644 --- a/Tests/GitKitTests/GitKitTests.swift +++ b/Tests/GitKitTests/GitKitTests.swift @@ -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() From 95749dfdc3d4dac431e6effd287690c9c88610d2 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:27:09 -0800 Subject: [PATCH 3/3] fix test build --- Tests/GitKitTests/GitKitTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/GitKitTests/GitKitTests.swift b/Tests/GitKitTests/GitKitTests.swift index 40f5a85..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.") }