adds nice git interface

This commit is contained in:
2026-10-30 13:21:45 +01:00
parent b9c03a7637
commit caec81e762
107 changed files with 6466 additions and 3992 deletions
@@ -21,6 +21,15 @@ import Testing
#expect(state.fileDiffs["a.txt"]?.isTooBig == false)
}
@Test("behind and upstream pass through from the snapshot")
func behindAndUpstream() {
let state = GitDerivation.derive(GitSnapshot(branch: "main", ahead: 1, canPush: true, behind: 2, upstream: "origin/main", changes: []))
#expect(state.behind == 2)
#expect(state.upstream == "origin/main")
#expect(GitDerivation.derive(nil).upstream == nil)
#expect(GitDerivation.derive(nil).behind == 0)
}
@Test("no snapshot means not a repository")
func notARepository() {
let state = GitDerivation.derive(nil)
@@ -105,48 +114,8 @@ import Testing
}
@Suite struct SourceControlTextTests {
private func change(_ path: String, staged: Bool = false) -> Change {
Change(path: path, status: .modified, added: 1, removed: 0, staged: staged)
}
@Test("one group per folder, even when git returns the folder in separate runs")
func oneGroupPerFolder() {
let groups = SourceControlText.groupByDir([
change("tests/Feature/AlphaTest.php"), change("app/Models/User.php"), change("tests/Feature/BetaTest.php"),
])
#expect(groups.map(\.dir) == ["tests/Feature", "app/Models"])
#expect(groups[0].rows.map(\.path) == ["tests/Feature/AlphaTest.php", "tests/Feature/BetaTest.php"])
}
@Test("every row is kept, so the keyboard cursor walks the full list")
func keepsEveryRow() {
let list = ["a/one.ts", "b/two.ts", "a/three.ts", "four.ts"].map { change($0) }
let flat = SourceControlText.groupByDir(list).flatMap(\.rows)
#expect(flat.count == list.count)
#expect(Set(flat.map(\.id)).count == list.count)
}
@Test("a project-root file sits in the empty-string group")
func rootGroup() {
#expect(SourceControlText.groupByDir([change("README.md")]) == [ChangeGroup(dir: "", rows: [change("README.md")])])
}
@Test("navigation walks staged groups before unstaged ones")
func navigationOrder() {
let order = SourceControlText.navigationOrder([change("b/x"), change("a/y", staged: true), change("b/z")])
#expect(order.map(\.path) == ["a/y", "b/x", "b/z"])
}
@Test("a dictated commit message becomes one lowercase line")
func commitMessage() {
#expect(SourceControlText.normalizeCommitMessage("Fix The Bug\n In Parser \r\n") == "fix the bug in parser ")
}
@Test("the push tooltip counts commits")
func pushTooltip() {
#expect(SourceControlText.pushTooltip(canPush: false, ahead: 0) == "Nothing to push (⌘P)")
#expect(SourceControlText.pushTooltip(canPush: true, ahead: 1) == "Push 1 commit to remote (⌘P)")
#expect(SourceControlText.pushTooltip(canPush: true, ahead: 3) == "Push 3 commits to remote (⌘P)")
#expect(SourceControlText.pushTooltip(canPush: true, ahead: 0) == "Push the branch to remote (⌘P)")
}
}