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
@@ -294,6 +294,39 @@ import Testing
#expect(harness.model.editor?.text(for: "a.php") == "committed")
}
@Test func cleanUpAsksFirstThenRunsGitAndReloadsTheFile() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false), ("new.txt", .added, false)]),
contents: ["a.php": "edited"])
await harness.start()
harness.model.open("a.php")
await harness.model.settle()
await harness.perform(.context(.gitCleanUp))
guard case let .confirm(request) = harness.model.overlay.current else {
Issue.record("expected a confirm overlay")
return
}
#expect(request.title == "Clean up 2 files?")
#expect(harness.git.executed.isEmpty)
harness.files.set("a.php", "staged")
await harness.perform(.confirmPending)
#expect(harness.git.executed == [["restore", "--worktree", "--", "."], ["clean", "-fd"]])
#expect(await eventually { harness.model.editor?.text(for: "a.php") == "staged" })
}
@Test func mergeAsksFirstThenRunsGit() async {
let harness = WorkspaceHarness(git: snapshot([]))
await harness.start()
await harness.perform(.context(.mergeBranch("feature")))
guard case let .confirm(request) = harness.model.overlay.current else {
Issue.record("expected a confirm overlay")
return
}
#expect(request.confirmLabel == "Merge")
#expect(harness.git.executed.isEmpty)
await harness.perform(.confirmPending)
#expect(harness.git.executed == [["merge", "--no-edit", "feature"]])
}
@Test func stagingRunsGitStraightAway() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false), ("b.php", .modified, false)]))
await harness.start()
@@ -353,6 +386,46 @@ import Testing
#expect(harness.toastTitles == ["Committed 1 file", "Pushed to origin/main"])
}
@Test func theCommitButtonCommitsWithoutPushingAndCommitAndPushPushes() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, true)]))
await harness.start()
harness.model.sourceControl?.setCommitMessage("fix it")
await harness.perform(.commit)
#expect(harness.git.executed == [["commit", "-m", "fix it"]])
let pushing = WorkspaceHarness(git: snapshot([("a.php", .modified, true)]))
await pushing.start()
pushing.model.sourceControl?.setCommitMessage("ship it")
await pushing.perform(.commitAndPush)
#expect(pushing.git.executed == [["commit", "-m", "ship it"], ["push"]])
}
@Test func theStageAllAndCommitCommandStagesThenCommitsWithoutPushing() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, false), ("new.txt", .added, false)]))
await harness.start()
harness.model.sourceControl?.setCommitMessage("ship it")
await harness.perform(.stageAllAndCommit)
#expect(harness.git.executed == [["add", "--", "a.php", "new.txt"], ["commit", "-m", "ship it"]])
}
@Test func theGenerateCommitMessageCommandFillsTheMessageAndFocusesIt() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, true)]))
await harness.start()
harness.commitMessages.setResult(.success("Fixed the login form"))
await harness.perform(.generateCommitMessage)
#expect(harness.model.sourceControl?.commitMessage == "fixed the login form")
#expect(harness.model.focusRequest?.target == .commitMessage)
#expect(harness.git.executed.isEmpty)
}
@Test func aFailedGenerationToastsOnce() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, true)]))
await harness.start()
harness.commitMessages.setResult(.failure(.timedOut))
await harness.perform(.generateCommitMessage)
#expect(harness.toastTitles == ["Couldn't generate a commit message"])
}
@Test func commitWithoutAMessageStillAsksGitThenFocusesTheMessage() async {
let harness = WorkspaceHarness(git: snapshot([("a.php", .modified, true)]))
await harness.start()
@@ -637,6 +710,46 @@ import Testing
}
}
@MainActor
@Suite struct TailLogModelTests {
@Test func tailLogShowsTheBlockAndCloseRemovesIt() async {
let harness = WorkspaceHarness()
await harness.perform(.context(.tailLog("storage/logs/laravel.log")))
#expect(harness.model.terminal.tailedPath == "storage/logs/laravel.log")
let tail = FakeTerminal()
harness.model.terminal.start(.tail, on: tail)
await harness.perform(.closeTail)
#expect(tail.terminations == 1)
#expect(harness.model.terminal.tailedPath == nil)
}
@Test func tailingASecondLogReplacesTheFirst() async {
let harness = WorkspaceHarness()
await harness.perform(.context(.tailLog("a.log")))
let first = FakeTerminal()
harness.model.terminal.start(.tail, on: first)
await harness.perform(.context(.tailLog("b.log")))
#expect(first.terminations == 1)
#expect(harness.model.terminal.tailedPath == "b.log")
}
@Test func aProjectSwitchEndsTheTailAndOpensWithout() async {
let harness = WorkspaceHarness()
await harness.start()
await harness.perform(.context(.tailLog("a.log")))
let tail = FakeTerminal()
harness.model.terminal.start(.tail, on: tail)
await harness.model.openProject(URL(fileURLWithPath: "/fake/other"))
#expect(tail.terminations == 1)
#expect(harness.model.terminal.tailedPath == nil)
}
@Test func theTailLogItemUsesThePlainTint() {
#expect(ContextMenuOverlay.tint(for: .tailLog("a.log")) == .plain)
#expect(ContextMenuOverlay.symbol(for: .tailLog("a.log")) == "terminal")
}
}
@MainActor
@Suite struct TerminalContextMenuModelTests {
@Test func aRightClickInATerminalOpensTheAppMenuAtThePointer() {