improves the git feature by adding a conflict status

This commit is contained in:
2026-10-30 16:47:34 +01:00
parent caec81e762
commit 0278d7fbd1
14 changed files with 10927 additions and 19 deletions
@@ -21,6 +21,18 @@ import Testing
#expect(state.fileDiffs["a.txt"]?.isTooBig == false)
}
@Test("a merge conflict is not counted as staged")
func conflictIsNotStaged() {
let state = GitDerivation.derive(GitSnapshot(branch: "main", ahead: 0, canPush: false, changes: [
change("both.txt", .unmerged, staged: false, "a\n", "<<<<<<< HEAD\na\n=======\nb\n>>>>>>> topic\n"),
change("ready.txt", .modified, staged: true, "1\n", "2\n"),
]))
#expect(state.stagedCount == 1)
#expect(state.unstagedCount == 1)
#expect(state.stagedPaths == ["ready.txt"])
#expect(state.unstagedPaths == ["both.txt"])
}
@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: []))
@@ -32,6 +32,14 @@ import Testing
#expect(GitSections.build([row("x", status, staged: false)]).map(\.kind) == [.changed])
}
@Test("a merge conflict lands in changed, not staged", arguments: [("U", "U"), ("A", "A"), ("D", "D")] as [(Character, Character)])
func conflictIsChanged(index: Character, working: Character) {
let rows = Porcelain.classify(index: index, working: working).map { row("both.txt", $0.status, staged: $0.staged) }
let sections = GitSections.build(rows)
#expect(sections.map(\.kind) == [.changed])
#expect(sections[0].rows.map(\.status) == [.unmerged])
}
@Test("empty sections are left out")
func emptySections() {
#expect(GitSections.build([]).isEmpty)
@@ -29,9 +29,9 @@ import Testing
])
}
@Test("a merge conflict stays one row", arguments: [("U", "U"), ("A", "A"), ("D", "D"), ("U", "D")] as [(Character, Character)])
@Test("a merge conflict stays one unstaged U row", arguments: [("U", "U"), ("A", "A"), ("D", "D"), ("U", "D")] as [(Character, Character)])
func conflict(index: Character, working: Character) {
#expect(Porcelain.classify(index: index, working: working) == [GitRowSpec(status: .modified, staged: true)])
#expect(Porcelain.classify(index: index, working: working) == [GitRowSpec(status: .unmerged, staged: false)])
}
// MARK: headers
@@ -188,6 +188,12 @@ import Testing
#expect(git.executed == [["restore", "--", "src/b.php"]])
}
@Test func aConflictIsNotAStagedFile() async {
let (store, _, _) = await makeStore(snapshot([("both.txt", .unmerged, false), ("config/app.json", .modified, true)]))
#expect(store.stagedPathCount == 1)
#expect(store.fileStatuses["both.txt"] == .unmerged)
}
@Test func unstagingLogsRestoreStaged() async {
let (store, git, _) = await makeStore()
await store.unstage(["config/app.json"])