feat(diff): add branch scope to context panel diff view
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
This commit is contained in:
@@ -428,6 +428,49 @@ export function registerGitRoutes(app) {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/git/branch-base', async (req, res) => {
|
||||
const { getBranchBase } = await getGitLibraries();
|
||||
try {
|
||||
const directory = resolveDirectoryQuery(req.query.directory);
|
||||
if (!directory) {
|
||||
return res.status(400).json({ error: 'directory parameter is required' });
|
||||
}
|
||||
|
||||
const branch = resolveDirectoryQuery(req.query.branch);
|
||||
if (!branch) {
|
||||
return res.status(400).json({ error: 'branch parameter is required' });
|
||||
}
|
||||
|
||||
const result = await getBranchBase(directory, branch);
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
console.error('Failed to get branch base:', error);
|
||||
res.status(500).json({ error: error.message || 'Failed to get branch base' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/git/range-files', async (req, res) => {
|
||||
const { getRangeFiles } = await getGitLibraries();
|
||||
try {
|
||||
const directory = resolveDirectoryQuery(req.query.directory);
|
||||
if (!directory) {
|
||||
return res.status(400).json({ error: 'directory parameter is required' });
|
||||
}
|
||||
|
||||
const base = resolveDirectoryQuery(req.query.base);
|
||||
const head = resolveDirectoryQuery(req.query.head);
|
||||
if (!base || !head) {
|
||||
return res.status(400).json({ error: 'base and head parameters are required' });
|
||||
}
|
||||
|
||||
const files = await getRangeFiles(directory, { base, head });
|
||||
res.json({ files });
|
||||
} catch (error) {
|
||||
console.error('Failed to get git range files:', error);
|
||||
res.status(500).json({ error: error.message || 'Failed to get git range files' });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/git/revert', async (req, res) => {
|
||||
const { revertFile } = await getGitLibraries();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user