From 6d3c2a45292a2b529bd58473f019f72ee8152f44 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 13:24:51 -0800 Subject: [PATCH 01/17] fix default branch name in tests --- Tests/GitKitTests/GitKitTests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/GitKitTests/GitKitTests.swift b/Tests/GitKitTests/GitKitTests.swift index 8eabc00..8bcd548 100644 --- a/Tests/GitKitTests/GitKitTests.swift +++ b/Tests/GitKitTests/GitKitTests.swift @@ -82,15 +82,15 @@ final class GitKitTests: XCTestCase { func testCommandWithArgs() throws { let path = self.currentPath() - try self._test(.cmd(.branch, "-a"), path: path, expectation: "* master") + try self._test(.cmd(.branch, "-a"), path: path, expectation: "* main") } func testClone() throws { let path = self.currentPath() let expectation = """ - On branch master - Your branch is up to date with 'origin/master'. + On branch main + Your branch is up to date with 'origin/main'. nothing to commit, working tree clean """ @@ -109,7 +109,7 @@ final class GitKitTests: XCTestCase { let path = self.currentPath() try self.clean(path: path) let expectedOutput = """ - On branch master + On branch main nothing to commit, working tree clean """ From 958abfe44c1f794b2343eb5898eb8d593bc8d1e2 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 13:46:35 -0800 Subject: [PATCH 02/17] fix more `master`->`main` in tests --- Tests/GitKitTests/GitKitTests.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Tests/GitKitTests/GitKitTests.swift b/Tests/GitKitTests/GitKitTests.swift index 8bcd548..5741ab1 100644 --- a/Tests/GitKitTests/GitKitTests.swift +++ b/Tests/GitKitTests/GitKitTests.swift @@ -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 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: "git@github.com: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 { From f934d304d9c71c65b5414c83905b9ceb7ac771d4 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 13:44:21 -0800 Subject: [PATCH 03/17] test: add github workflow and makefile --- .github/workflows/test.yml | 22 ++++++++++++++++++++++ Makefile | 3 +++ 2 files changed, 25 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 Makefile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5e7fa4a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +# this file is hardlinked so that it exists as both //.github/workflows/test.yml and //test.yml. this is because Swift package manager will not pull in hidden files into the generated Xcode project when opened from package.swift + +name: Test +on: + push: + branches: + - main + + pull_request: + paths: + - "Sources/**" + - "Tests/**" + - ".github/workflows/test.yml" + +jobs: + test: + name: Test + runs-on: macos-13 + steps: + - uses: actions/checkout@v4 + - run: make test + \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..12c3390 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +.PHONY: test +test: + swift test \ No newline at end of file From 43f11e3a69d3bac53aedd0013173cd8e7c83a60c Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 13:44:53 -0800 Subject: [PATCH 04/17] remove hardlink note; it doesnt work --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5e7fa4a..8463a9b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,3 @@ -# this file is hardlinked so that it exists as both //.github/workflows/test.yml and //test.yml. this is because Swift package manager will not pull in hidden files into the generated Xcode project when opened from package.swift - name: Test on: push: From 6e4399f557a928a6c15fb5fe799c6e9c3a66db3c Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 13:58:43 -0800 Subject: [PATCH 05/17] debug test logic --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8463a9b..623d958 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,5 +16,13 @@ jobs: runs-on: macos-13 steps: - uses: actions/checkout@v4 + - name: Replicate failing test logic + run: | + mkdir test + pushd test + git init + git commit -m 'initial' --allow-empty --no-gpg-sign + git branch -a + popd - run: make test \ No newline at end of file From 4657b4eaf314d617bf70c1e91a29b504188e4efb Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:05:26 -0800 Subject: [PATCH 06/17] remove debug; run tests on linux too --- .github/workflows/test.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 623d958..3098810 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,18 +11,15 @@ on: - ".github/workflows/test.yml" jobs: - test: - name: Test - runs-on: macos-13 + test-macos: + name: Test on macOS + runs-on: macos-15 steps: - uses: actions/checkout@v4 - - name: Replicate failing test logic - run: | - mkdir test - pushd test - git init - git commit -m 'initial' --allow-empty --no-gpg-sign - git branch -a - popd - run: make test - \ No newline at end of file + test-linux: + name: Test on Linux + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: make test \ No newline at end of file From 6aa6e3b34e173824d150772d652c60458dea552d Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:06:54 -0800 Subject: [PATCH 07/17] fix default branch name in tests --- .github/workflows/test.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3098810..d77bb30 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,15 +11,17 @@ on: - ".github/workflows/test.yml" jobs: - test-macos: - name: Test on macOS - runs-on: macos-15 - steps: - - uses: actions/checkout@v4 - - run: make test - test-linux: - name: Test on Linux - runs-on: ubuntu-latest + test: + name: Run tests + strategy: + matrix: + os: [macos-15, macos-14] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + + # there are unit tests that rely on the default branch name being `main` + - name: Set Git default branch name + run: git config --global init.defaultBranch main + - run: make test \ No newline at end of file From ae12105cef07390ba7cc731a7e8ebca0a140e415 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:07:21 -0800 Subject: [PATCH 08/17] fix os image names --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d77bb30..9534be4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: name: Run tests strategy: matrix: - os: [macos-15, macos-14] + os: [macos-15, ubuntu-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 From 05b1007db38fd1abe41eb18bdff200301b0b7b70 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:09:55 -0800 Subject: [PATCH 09/17] make http instead of ssh to pass in ci --- 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 5741ab1..09d0af2 100644 --- a/Tests/GitKitTests/GitKitTests.swift +++ b/Tests/GitKitTests/GitKitTests.swift @@ -98,7 +98,7 @@ final class GitKitTests: XCTestCase { try self.clean(path: path) let git = Git(path: path) - try git.run(.clone(url: "git@github.com:binarybirds/shell-kit")) + try git.run(.clone(url: "https://github.com/binarybirds/shell-kit.git")) let statusOutput = try git.run("cd \(path)/shell-kit && git status") try self.clean(path: path) self.assert(type: "output", result: statusOutput, expected: expectation) From 132740cd5567106b06a1b7e00b648d2090c42ecd Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:11:22 -0800 Subject: [PATCH 10/17] missed one --- 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 09d0af2..823f19d 100644 --- a/Tests/GitKitTests/GitKitTests.swift +++ b/Tests/GitKitTests/GitKitTests.swift @@ -117,7 +117,7 @@ final class GitKitTests: XCTestCase { try self.clean(path: path) let git = Git(path: path) - try git.run(.clone(url: "git@github.com:binarybirds/shell-kit", dirName: "MyCustomDirectory")) + 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) From b990e9996af304b526196d54276fc4a36e3e968a Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:12:15 -0800 Subject: [PATCH 11/17] comment --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9534be4..d8833e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: steps: - uses: actions/checkout@v4 - # there are unit tests that rely on the default branch name being `main` + # there are unit tests that rely on the default branch name being `main` but this isn't the case on GitHub Actions runners - name: Set Git default branch name run: git config --global init.defaultBranch main From a5b1f267d62688b9cf4c08a5238e7f5120e4a8ce Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:12:45 -0800 Subject: [PATCH 12/17] run only on mac --- .github/workflows/test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8833e8..f2340d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,10 +13,7 @@ on: jobs: test: name: Run tests - strategy: - matrix: - os: [macos-15, ubuntu-latest] - runs-on: ${{ matrix.os }} + runs-on: macos-15 steps: - uses: actions/checkout@v4 From 3bbaea33bbd2e6a3c5fb1596bbe845db3e21f181 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:17:45 -0800 Subject: [PATCH 13/17] newlines at eof --- .github/workflows/test.yml | 2 +- Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f2340d3..f342ca1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,4 +21,4 @@ jobs: - name: Set Git default branch name run: git config --global init.defaultBranch main - - run: make test \ No newline at end of file + - run: make test diff --git a/Makefile b/Makefile index 12c3390..772d29a 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ .PHONY: test test: - swift test \ No newline at end of file + swift test From 2d9eafb079bfad438105cf3989a87266869bba89 Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sat, 19 Jul 2025 14:24:04 -0800 Subject: [PATCH 14/17] moving new test method to correct branch --- Tests/GitKitTests/GitKitTests.swift | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Tests/GitKitTests/GitKitTests.swift b/Tests/GitKitTests/GitKitTests.swift index 823f19d..203acc5 100644 --- a/Tests/GitKitTests/GitKitTests.swift +++ b/Tests/GitKitTests/GitKitTests.swift @@ -103,25 +103,6 @@ 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 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 { From ccded26a12efc6acc52b16130ffe5f858867b27d Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Sun, 9 Feb 2025 15:13:24 -0900 Subject: [PATCH 15/17] 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 16/17] 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 17/17] 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.") }