Show every change on the current branch relative to its base in the Changed/Staged/Last turn dropdown. The base comes from the branch's reflog record or an explicit per-branch user choice (persisted), never a main/master guess; when git has no record the user picks a base once from a searchable branch list. - server: GET /api/git/branch-base (reflog-derived base), GET /api/git/range-files (name-status -z with rename/copy destination paths and -C copy detection) - shared UI: optional getBranchBase/getGitRangeFiles runtime APIs with boundary parsing; persisted per-branch overrides keyed by runtime+directory+branch - DiffView: branch scope with confirmed-unavailability coercion of persisted tabs (detached HEAD, default-branch checkout, metadata settled without a default), range-invalidated diff cache guarded against stale completions, bounded branch-metadata retry, read-only diff actions in branch scope; hidden in VS Code - helper module branchDiffScope.ts with tests for coercion, availability, race conditions, and retry exhaustion
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import { beforeEach, describe, expect, mock, test } from "bun:test"
|
|
|
|
let runtimeKey = "runtime-a"
|
|
mock.module("@/lib/runtime-switch", () => ({ getRuntimeKey: () => runtimeKey }))
|
|
|
|
const { gitBaseBranchEntryKey, useGitBaseBranchStore } = await import("./useGitBaseBranchStore")
|
|
|
|
describe("git base branch overrides", () => {
|
|
beforeEach(() => {
|
|
runtimeKey = "runtime-a"
|
|
useGitBaseBranchStore.setState({ overrides: {} })
|
|
})
|
|
|
|
test("keys the same repository per branch and runtime", () => {
|
|
const featureA = gitBaseBranchEntryKey("/repo", "feature-a")
|
|
const featureB = gitBaseBranchEntryKey("/repo", "feature-b")
|
|
runtimeKey = "runtime-b"
|
|
const featureARemote = gitBaseBranchEntryKey("/repo", "feature-a")
|
|
|
|
expect(new Set([featureA, featureB, featureARemote]).size).toBe(3)
|
|
})
|
|
|
|
test("a base picked for one branch does not apply to another branch", () => {
|
|
const store = useGitBaseBranchStore.getState()
|
|
store.setOverride("/repo", "feature-a", "main")
|
|
|
|
expect(store.getOverride("/repo", "feature-a")).toBe("main")
|
|
// feature-b must fall back to its own detection, not feature-a's choice.
|
|
expect(store.getOverride("/repo", "feature-b")).toBeNull()
|
|
})
|
|
|
|
test("different branches of one repository keep independent bases", () => {
|
|
const store = useGitBaseBranchStore.getState()
|
|
store.setOverride("/repo", "feature-a", "main")
|
|
store.setOverride("/repo", "feature-b", "develop")
|
|
|
|
expect(store.getOverride("/repo", "feature-a")).toBe("main")
|
|
expect(store.getOverride("/repo", "feature-b")).toBe("develop")
|
|
})
|
|
|
|
test("clearOverride removes only the targeted branch's choice", () => {
|
|
const store = useGitBaseBranchStore.getState()
|
|
store.setOverride("/repo", "feature-a", "main")
|
|
store.setOverride("/repo", "feature-b", "develop")
|
|
store.clearOverride("/repo", "feature-a")
|
|
|
|
expect(store.getOverride("/repo", "feature-a")).toBeNull()
|
|
expect(store.getOverride("/repo", "feature-b")).toBe("develop")
|
|
})
|
|
|
|
test("rejects empty directory, branch, or base", () => {
|
|
const store = useGitBaseBranchStore.getState()
|
|
store.setOverride("", "feature-a", "main")
|
|
store.setOverride("/repo", "", "main")
|
|
store.setOverride("/repo", "feature-a", "")
|
|
store.clearOverride("", "feature-a")
|
|
|
|
expect(useGitBaseBranchStore.getState().overrides).toEqual({})
|
|
expect(store.getOverride("", "feature-a")).toBeNull()
|
|
expect(store.getOverride("/repo", "")).toBeNull()
|
|
})
|
|
})
|