Git - better error handling for git merge-base (#198208)

This commit is contained in:
Ladislau Szomoru 2023-11-14 14:51:17 +01:00 committed by GitHub
parent 67aa71296f
commit ed30010d3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 8 deletions

View file

@ -189,7 +189,7 @@ export class ApiRepository implements Repository {
return this.repository.getRefs(query, cancellationToken);
}
getMergeBase(ref1: string, ref2: string): Promise<string> {
getMergeBase(ref1: string, ref2: string): Promise<string | undefined> {
return this.repository.getMergeBase(ref1, ref2);
}

View file

@ -233,7 +233,7 @@ export interface Repository {
getRefs(query: RefQuery, cancellationToken?: CancellationToken): Promise<Ref[]>;
getMergeBase(ref1: string, ref2: string): Promise<string>;
getMergeBase(ref1: string, ref2: string): Promise<string | undefined>;
tag(name: string, upstream: string): Promise<void>;
deleteTag(name: string): Promise<void>;

View file

@ -1434,11 +1434,16 @@ export class Repository {
return result;
}
async getMergeBase(ref1: string, ref2: string): Promise<string> {
const args = ['merge-base', ref1, ref2];
const result = await this.exec(args);
async getMergeBase(ref1: string, ref2: string): Promise<string | undefined> {
try {
const args = ['merge-base', ref1, ref2];
const result = await this.exec(args);
return result.stdout.trim();
return result.stdout.trim();
}
catch (err) {
return undefined;
}
}
async hashObject(data: string): Promise<string> {

View file

@ -175,7 +175,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
async resolveHistoryItemGroupCommonAncestor(refId1: string, refId2: string): Promise<{ id: string; ahead: number; behind: number } | undefined> {
const ancestor = await this.repository.getMergeBase(refId1, refId2);
if (ancestor === '') {
if (!ancestor) {
return undefined;
}

View file

@ -1189,7 +1189,7 @@ export class Repository implements Disposable {
return this.run(Operation.Diff, () => this.repository.diffBetweenShortStat(ref1, ref2));
}
getMergeBase(ref1: string, ref2: string): Promise<string> {
getMergeBase(ref1: string, ref2: string): Promise<string | undefined> {
return this.run(Operation.MergeBase, () => this.repository.getMergeBase(ref1, ref2));
}