Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/git/src/api/api1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/git/src/api/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down
13 changes: 9 additions & 4 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion extensions/git/src/historyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/git/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down