feat(FN-4425): complete Step 1 — add root-branch diff-base helper
Fusion-Task-Id: FN-4425 Fusion-Task-Lineage: 5e45b534-6a18-4f27-81d9-88cce3ec9344
This commit is contained in:
@@ -41,6 +41,44 @@ const fileDiffsCache = new Map<
|
|||||||
|
|
||||||
type DoneTaskFileStatus = "added" | "modified" | "deleted" | "renamed";
|
type DoneTaskFileStatus = "added" | "modified" | "deleted" | "renamed";
|
||||||
|
|
||||||
|
type BranchFallbackTask = {
|
||||||
|
branch?: string | null;
|
||||||
|
baseBranch?: string;
|
||||||
|
baseCommitSha?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function resolveTaskBranchRef(task: BranchFallbackTask, rootDir: string): Promise<string | undefined> {
|
||||||
|
const branch = task.branch?.trim();
|
||||||
|
if (!branch) return undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const resolved = (await runGitCommand(["rev-parse", "--verify", "--quiet", branch], rootDir, 5000)).trim();
|
||||||
|
if (resolved) return branch;
|
||||||
|
} catch {
|
||||||
|
// continue to refs/heads fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
const headsRef = `refs/heads/${branch}`;
|
||||||
|
try {
|
||||||
|
const resolved = (await runGitCommand(["rev-parse", "--verify", "--quiet", headsRef], rootDir, 5000)).trim();
|
||||||
|
if (resolved) return headsRef;
|
||||||
|
} catch {
|
||||||
|
// unresolved
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolveBranchDiffBaseInRoot(task: BranchFallbackTask, rootDir: string): Promise<{ baseRef: string; branchRef: string } | undefined> {
|
||||||
|
const branchRef = await resolveTaskBranchRef(task, rootDir);
|
||||||
|
if (!branchRef) return undefined;
|
||||||
|
|
||||||
|
const baseRef = await resolveDiffBase(task, rootDir, branchRef, runGitCommand, { enableDisplayRecovery: true });
|
||||||
|
if (!baseRef) return undefined;
|
||||||
|
|
||||||
|
return { baseRef, branchRef };
|
||||||
|
}
|
||||||
|
|
||||||
type AggregatedDoneTaskFile = {
|
type AggregatedDoneTaskFile = {
|
||||||
path: string;
|
path: string;
|
||||||
status: DoneTaskFileStatus;
|
status: DoneTaskFileStatus;
|
||||||
|
|||||||
Reference in New Issue
Block a user