finished better review prep (better execution capture of git)
This commit is contained in:
@@ -19,10 +19,7 @@ import {
|
|||||||
buildConflictResolutionPrompt,
|
buildConflictResolutionPrompt,
|
||||||
MAX_DIFF_BYTES,
|
MAX_DIFF_BYTES,
|
||||||
} from "./prompts";
|
} from "./prompts";
|
||||||
import {
|
import { compileIgnorePatterns } from "./diff";
|
||||||
compileIgnorePatterns,
|
|
||||||
type DiffOptions,
|
|
||||||
} from "./diff";
|
|
||||||
import { extractReflection } from "./reflection";
|
import { extractReflection } from "./reflection";
|
||||||
import {
|
import {
|
||||||
extractReview,
|
extractReview,
|
||||||
@@ -49,6 +46,7 @@ import {
|
|||||||
ensureDir,
|
ensureDir,
|
||||||
captureGitCommits,
|
captureGitCommits,
|
||||||
captureGitHead,
|
captureGitHead,
|
||||||
|
canComputeRange,
|
||||||
getCommitRangeDiff,
|
getCommitRangeDiff,
|
||||||
hasUncommittedChanges,
|
hasUncommittedChanges,
|
||||||
getGitStatusPorcelain,
|
getGitStatusPorcelain,
|
||||||
@@ -918,6 +916,15 @@ async function executeTask(
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Cheap guard mirroring canCompareToBase: if the captured base ref no
|
||||||
|
// longer resolves (stale/broken worktree ref), warn explicitly and
|
||||||
|
// never treat the task as review-verified.
|
||||||
|
if (!canComputeRange(worktreeDir, baseRef)) {
|
||||||
|
sendChatMessage?.(
|
||||||
|
`~ review for ${task.id} · ${task.title} — diff could not be computed (base ref ${baseRef} no longer resolves)`,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
const rangeDiff = getCommitRangeDiff(worktreeDir, baseRef);
|
const rangeDiff = getCommitRangeDiff(worktreeDir, baseRef);
|
||||||
if (rangeDiff.kind === "error") {
|
if (rangeDiff.kind === "error") {
|
||||||
sendChatMessage?.(
|
sendChatMessage?.(
|
||||||
|
|||||||
11
src/utils.ts
11
src/utils.ts
@@ -930,7 +930,10 @@ export function canComputeRange(projectDir: string, baseRef: string): boolean {
|
|||||||
const { execSync } = require("node:child_process");
|
const { execSync } = require("node:child_process");
|
||||||
if (!/^[0-9a-f]{7,40}$/i.test(baseRef)) return false;
|
if (!/^[0-9a-f]{7,40}$/i.test(baseRef)) return false;
|
||||||
try {
|
try {
|
||||||
execSync(`git rev-parse --verify ${baseRef}`, {
|
// git cat-file -e truly verifies the object EXISTS (rev-parse --verify
|
||||||
|
// accepts any 40-hex SHA even if it was never created), so a stale/broken
|
||||||
|
// base ref is caught here rather than silently treated as no-changes.
|
||||||
|
execSync(`git cat-file -e ${baseRef}`, {
|
||||||
cwd: projectDir,
|
cwd: projectDir,
|
||||||
stdio: "pipe",
|
stdio: "pipe",
|
||||||
});
|
});
|
||||||
@@ -961,9 +964,11 @@ export function getCommitRangeDiff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify the base ref resolves before diffing — a stale/unfetched ref is a
|
// Verify the base ref resolves before diffing — a stale/unfetched ref is a
|
||||||
// computation failure, not a clean "no changes" signal.
|
// computation failure, not a clean "no changes" signal. git cat-file -e
|
||||||
|
// checks the object genuinely exists (rev-parse --verify would accept any
|
||||||
|
// 40-hex SHA even if it was never created).
|
||||||
try {
|
try {
|
||||||
execSync(`git rev-parse --verify ${baseRef}`, {
|
execSync(`git cat-file -e ${baseRef}`, {
|
||||||
cwd: projectDir,
|
cwd: projectDir,
|
||||||
stdio: "pipe",
|
stdio: "pipe",
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user