Git - use git diff-tree only for the first commit in the repository (#274107)

This commit is contained in:
Ladislau Szomoru
2025-10-30 16:53:37 +00:00
committed by GitHub
parent 16f58dd3ac
commit d2c16dbf3e
2 changed files with 38 additions and 3 deletions

View File

@@ -1688,9 +1688,8 @@ export class Repository {
return result.stdout.trim();
}
async diffBetween2(ref1: string, ref2: string, options: { similarityThreshold?: number; symmetric?: boolean }): Promise<Change[]> {
const range = options.symmetric ? `${ref1}...${ref2}` : `${ref1}..${ref2}`;
return await this.diffFiles(range, { cached: false, similarityThreshold: options.similarityThreshold });
async diffBetween2(ref1: string, ref2: string, options: { similarityThreshold?: number }): Promise<Change[]> {
return await this.diffFiles(`${ref1}...${ref2}`, { cached: false, similarityThreshold: options.similarityThreshold });
}
private async diffFiles(ref: string | undefined, options: { cached: boolean; similarityThreshold?: number }): Promise<Change[]> {
@@ -1718,6 +1717,29 @@ export class Repository {
return parseGitChanges(this.repositoryRoot, gitResult.stdout);
}
async diffTrees(treeish1: string, treeish2?: string, options?: { similarityThreshold?: number }): Promise<Change[]> {
const args = ['diff-tree', '-r', '--name-status', '-z', '--diff-filter=ADMR'];
if (options?.similarityThreshold) {
args.push(`--find-renames=${options.similarityThreshold}%`);
}
args.push(treeish1);
if (treeish2) {
args.push(treeish2);
}
args.push('--');
const gitResult = await this.exec(args);
if (gitResult.exitCode) {
return [];
}
return parseGitChanges(this.repositoryRoot, gitResult.stdout);
}
async getMergeBase(ref1: string, ref2: string, ...refs: string[]): Promise<string | undefined> {
try {
const args = ['merge-base'];