diff --git a/.changeset/metal-chefs-dream.md b/.changeset/metal-chefs-dream.md new file mode 100644 index 00000000..2f64c6dd --- /dev/null +++ b/.changeset/metal-chefs-dream.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Added a dedicated git getDiffCount function to reduce git operations diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 38093d5d..4918488f 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -562,9 +562,8 @@ export class Cline { return false } - // Get changed files between current state and commit - const changedFiles = await this.checkpointTracker?.getDiffSet(previousCheckpointHash, hash) - const changedFilesCount = changedFiles?.length || 0 + // Get count of changed files between current state and commit + const changedFilesCount = (await this.checkpointTracker?.getDiffCount(previousCheckpointHash, hash)) || 0 if (changedFilesCount > 0) { return true } diff --git a/src/integrations/checkpoints/CheckpointTracker.ts b/src/integrations/checkpoints/CheckpointTracker.ts index 28958222..10277779 100644 --- a/src/integrations/checkpoints/CheckpointTracker.ts +++ b/src/integrations/checkpoints/CheckpointTracker.ts @@ -310,6 +310,29 @@ class CheckpointTracker { return result } + + /** + * Returns the number of files changed between two commits. + * + * @param lhsHash - The commit to compare from (older commit) + * @param rhsHash - The commit to compare to (newer commit). + * If omitted, we compare to the working directory. + * @returns The number of files changed between the commits + */ + public async getDiffCount(lhsHash: string, rhsHash?: string): Promise { + const gitPath = await getShadowGitPath(this.globalStoragePath, this.taskId, this.cwdHash) + const git = simpleGit(path.dirname(gitPath)) + + console.info(`Getting diff count between commits: ${lhsHash || "initial"} -> ${rhsHash || "working directory"}`) + + // Stage all changes so that untracked files appear in diff summary + await this.gitOperations.addCheckpointFiles(git) + + const diffRange = rhsHash ? `${lhsHash}..${rhsHash}` : lhsHash + const diffSummary = await git.diffSummary([diffRange]) + + return diffSummary.files.length + } } export default CheckpointTracker