feat: add diffBranchesStat and diffFileSingle to BranchManager

Adds FileStatEntry type and two new primitives to the BranchManager
port and SimpleGitBranchManager adapter, enabling split diff
procedures in the tRPC layer without returning raw multi-megabyte diffs.

- FileStatEntry captures path, status, additions/deletions, oldPath
  (renames), and optional projectId for multi-project routing
- diffBranchesStat uses --name-status + --numstat, detects binary
  files (shown as - / - in numstat), handles spaces in filenames
- diffFileSingle returns raw unified diff for a single file path
This commit is contained in:
Lukas May
2026-03-06 19:33:47 +01:00
parent 2eccde0ee1
commit 9894cdd06f
6 changed files with 290 additions and 2 deletions

View File

@@ -6,7 +6,7 @@
* a worktree to be checked out.
*/
import type { MergeResult, MergeabilityResult, BranchCommit } from './types.js';
import type { MergeResult, MergeabilityResult, BranchCommit, FileStatEntry } from './types.js';
export interface BranchManager {
/**
@@ -29,6 +29,22 @@ export interface BranchManager {
*/
diffBranches(repoPath: string, baseBranch: string, headBranch: string): Promise<string>;
/**
* Get per-file metadata for changes between two branches.
* Uses three-dot diff (baseBranch...headBranch) — same divergence model as diffBranches.
* Binary files are included with status 'binary' and additions/deletions both 0.
* Does NOT return hunk content.
*/
diffBranchesStat(repoPath: string, baseBranch: string, headBranch: string): Promise<FileStatEntry[]>;
/**
* Get the raw unified diff for a single file between two branches.
* Uses three-dot diff (baseBranch...headBranch).
* Returns empty string for binary files (caller must detect binary separately).
* filePath must be URL-decoded before being passed here.
*/
diffFileSingle(repoPath: string, baseBranch: string, headBranch: string, filePath: string): Promise<string>;
/**
* Delete a branch. No-op if the branch doesn't exist.
*/