adds claude-generated commit messages and a recent commits panel to the git view - adds log tailing in the explorer, branch merging and a clean up button

This commit is contained in:
2026-11-04 10:07:52 +01:00
parent 600d4874d2
commit cc6651c08a
49 changed files with 1944 additions and 180 deletions
@@ -207,6 +207,34 @@ import Testing
let service = GitService(root: worktree)
#expect(await service.isRepository())
}
@Test func recentCommitsReadHeadNewestFirst() async throws {
let repo = try repo()
let before = await GitService(root: repo.root).recentCommits().count
try repo.commit(["c.txt": "c\n"], message: "add \"c\" | 100% done")
let commits = await GitService(root: repo.root).recentCommits()
#expect(commits.count == before + 1)
let commit = try #require(commits.first)
#expect(commit.subject == "add \"c\" | 100% done")
#expect(commit.author == "Helder Tests")
#expect(!commit.hash.isEmpty)
#expect(abs(commit.date.timeIntervalSinceNow) < 600)
}
@Test func recentCommitsStopAtThirty() async throws {
let repo = try repo()
for index in 0..<32 {
try repo.commit(["n.txt": "\(index)\n"], message: "commit \(index)")
}
let commits = await GitService(root: repo.root).recentCommits()
#expect(commits.count == GitCommitLogParsing.limit)
#expect(commits.first?.subject == "commit 31")
}
@Test func aRepositoryWithoutCommitsHasNoRecentCommits() async throws {
let repo = try TempGitRepo()
#expect(await GitService(root: repo.root).recentCommits().isEmpty)
}
}
/// Names git would read as globs or options unless every pathspec is literal.
@@ -232,3 +260,30 @@ import Testing
#expect(runner.calls.allSatisfy { $0.environment?["GIT_LITERAL_PATHSPECS"] == "1" })
}
}
@Suite struct GitServiceStagedDiffTests {
@Test func stagedDiffHoldsOnlyTheStagedChanges() async throws {
let repo = try TempGitRepo()
try repo.commit(["a.txt": "1\n", "b.txt": "1\n"], message: "init")
try repo.write("a.txt", "1\nstaged\n")
try repo.run("add", "a.txt")
try repo.write("b.txt", "1\nunstaged\n")
let diff = try #require(await GitService(root: repo.root).stagedDiff())
#expect(diff.stat.contains("a.txt"))
#expect(!diff.stat.contains("b.txt"))
#expect(diff.patch.contains("+staged"))
#expect(!diff.patch.contains("unstaged"))
}
@Test func nothingStagedIsAnEmptyDiff() async throws {
let repo = try TempGitRepo()
try repo.commit(["a.txt": "1\n"], message: "init")
let diff = try #require(await GitService(root: repo.root).stagedDiff())
#expect(diff.isEmpty)
}
@Test func outsideARepositoryThereIsNoDiff() async throws {
let dir = try TempDirectory()
#expect(await GitService(root: dir.root).stagedDiff() == nil)
}
}