Skip to content

Commit e9d3591

Browse files
armcknightAndrew McKnighttib
authored
add custom directory name parameter to clone command (#3)
* fix default branch name in tests * fix more `master`->`main` in tests * test: add github workflow and makefile * remove hardlink note; it doesnt work * debug test logic * remove debug; run tests on linux too * fix default branch name in tests * fix os image names * make http instead of ssh to pass in ci * missed one * comment * run only on mac * newlines at eof * moving new test method to correct branch * add custom directory name parameter to clone command * moving new test method to correct branch * fix test build --------- Co-authored-by: Andrew McKnight <git@mcknight.rocks> Co-authored-by: Tibor Bödecs <mail.tib@gmail.com>
1 parent e481781 commit e9d3591

2 files changed

Lines changed: 23 additions & 25 deletions

File tree

Sources/GitKit/Git.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@ public final class Git: Shell {
1616
case cmd(Command, String? = nil)
1717
case addAll
1818
case status(short: Bool = false)
19+
case clone(url: String , dirName: String? = nil)
1920
case commit(message: String, allowEmpty: Bool = false, gpgSigned: Bool = false)
2021
case writeConfig(name: String, value: String)
2122
case readConfig(name: String)
22-
case clone(url: String)
23-
24-
/// - parameter branch the name of the branch to checkout
25-
/// - parameter create whether to create a new branch or checkout an existing one
26-
/// - parameter tracking when creating a new branch, the name of the remote branch it should track
27-
case checkout(branch: String, create: Bool = false, tracking: String? = nil)
28-
23+
case checkout(branch: String, create: Bool = false)
2924
case log(numberOfCommits: Int? = nil, options: [String]? = nil, revisions: String? = nil)
3025
case push(remote: String? = nil, branch: String? = nil)
3126
case pull(remote: String? = nil, branch: String? = nil, rebase: Bool = false)
@@ -69,20 +64,21 @@ public final class Git: Shell {
6964
}
7065
if gpgSigned {
7166
params.append("--gpg-sign")
72-
} else {
67+
}
68+
else {
7369
params.append("--no-gpg-sign")
7470
}
75-
case .clone(let url):
71+
case .clone(let url, let dirname):
7672
params = [Command.clone.rawValue, url]
77-
case .checkout(let branch, let create, let tracking):
73+
if let dirName = dirname {
74+
params.append(dirName)
75+
}
76+
case .checkout(let branch, let create):
7877
params = [Command.checkout.rawValue]
7978
if create {
8079
params.append("-b")
8180
}
8281
params.append(branch)
83-
if let tracking {
84-
params.append(tracking)
85-
}
8682
case .log(let numberOfCommits, let options, let revisions):
8783
params = [Command.log.rawValue]
8884
if let numberOfCommits = numberOfCommits {

Tests/GitKitTests/GitKitTests.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ final class GitKitTests: XCTestCase {
2525
("testLog", testLog),
2626
("testCommandWithArgs", testCommandWithArgs),
2727
("testClone", testClone),
28-
("testCheckoutRemoteTracking", testCheckoutRemoteTracking),
2928
("testRevParse", testRevParse),
3029
]
3130

@@ -106,26 +105,29 @@ final class GitKitTests: XCTestCase {
106105
self.assert(type: "output", result: statusOutput, expected: expectation)
107106
}
108107

109-
func testCheckoutRemoteTracking() throws {
108+
109+
func testCloneWithDirectory() throws {
110110
let path = self.currentPath()
111+
112+
let expectation = """
113+
On branch main
114+
Your branch is up to date with 'origin/main'.
115+
116+
nothing to commit, working tree clean
117+
"""
118+
111119
try self.clean(path: path)
112120
let git = Git(path: path)
113121

114-
try git.run(.clone(url: "https://github.com/binarybirds/shell-kit.git"))
115-
116-
let repoPath = "\(path)/shell-kit"
117-
let repoGit = Git(path: repoPath)
118-
119-
try repoGit.run(.checkout(branch: "feature-branch", create: true, tracking: "origin/main"))
120-
let branchOutput = try repoGit.run(.raw("branch -vv"))
122+
try git.run(.clone(url: "https://github.com/binarybirds/shell-kit.git", dirName: "MyCustomDirectory"))
123+
let statusOutput = try git.run("cd \(path)/MyCustomDirectory && git status")
121124
try self.clean(path: path)
122-
123-
XCTAssertTrue(branchOutput.contains("feature-branch"), "New branch should be created")
124-
XCTAssertTrue(branchOutput.contains("origin/main"), "Branch should track origin/main")
125+
self.assert(type: "output", result: statusOutput, expected: expectation)
125126
}
126127

127128
func testRevParse() throws {
128129
let path = self.currentPath()
130+
129131
try self.clean(path: path)
130132
let git = Git(path: path)
131133

0 commit comments

Comments
 (0)