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 - add missing error handler #201160

Merged
merged 1 commit into from
Dec 18, 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
3 changes: 2 additions & 1 deletion extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,8 @@ export class Repository {
return branch;
}

return Promise.reject<Branch>(new Error(`No such branch: ${name}`));
this.logger.warn(`No such branch: ${name}.`);
return Promise.reject<Branch>(new Error(`No such branch: ${name}.`));
}

async getDefaultBranch(): Promise<Branch> {
Expand Down
33 changes: 19 additions & 14 deletions extensions/git/src/historyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/


import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryItemGroup, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, l10n } from 'vscode';
import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryItemGroup, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, l10n, LogOutputChannel } from 'vscode';
import { Repository, Resource } from './repository';
import { IDisposable, filterEvent } from './util';
import { toGitUri } from './uri';
Expand Down Expand Up @@ -33,7 +33,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec

private disposables: Disposable[] = [];

constructor(protected readonly repository: Repository) {
constructor(protected readonly repository: Repository, private readonly logger: LogOutputChannel) {
this.disposables.push(repository.onDidRunGitStatus(this.onDidRunGitStatus, this));
this.disposables.push(filterEvent(repository.onDidRunOperation, e => e.operation === Operation.Refresh)(() => this._onDidChangeCurrentHistoryItemGroup.fire()));

Expand Down Expand Up @@ -157,19 +157,24 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
}

// Branch base
const branchBase = await this.repository.getBranchBase(historyItemGroupId);

if (branchBase?.name && branchBase?.type === RefType.Head) {
return {
id: `refs/heads/${branchBase.name}`,
label: branchBase.name
};
try {
const branchBase = await this.repository.getBranchBase(historyItemGroupId);

if (branchBase?.name && branchBase?.type === RefType.Head) {
return {
id: `refs/heads/${branchBase.name}`,
label: branchBase.name
};
}
if (branchBase?.name && branchBase.remote && branchBase?.type === RefType.RemoteHead) {
return {
id: `refs/remotes/${branchBase.remote}/${branchBase.name}`,
label: `${branchBase.remote}/${branchBase.name}`
};
}
}
if (branchBase?.name && branchBase.remote && branchBase?.type === RefType.RemoteHead) {
return {
id: `refs/remotes/${branchBase.remote}/${branchBase.name}`,
label: `${branchBase.remote}/${branchBase.name}`
};
catch (err) {
this.logger.error(`Failed to get branch base for '${historyItemGroupId}': ${err.message}`);
}

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 @@ -850,7 +850,7 @@ export class Repository implements Disposable {

this._sourceControl.quickDiffProvider = this;

const historyProvider = new GitHistoryProvider(this);
const historyProvider = new GitHistoryProvider(this, logger);
this._sourceControl.historyProvider = historyProvider;
this.disposables.push(historyProvider);

Expand Down