Skip to content

Commit

Permalink
Better error message when we can't fetch the default branch (#6655)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 authored Feb 12, 2025
1 parent 9c60049 commit a692853
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/github/folderRepositoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,17 @@ export class FolderRepositoryManager extends Disposable {

// respect the git setting to fetch before checkout
if (vscode.workspace.getConfiguration(GIT).get<boolean>(PULL_BEFORE_CHECKOUT, false) && branchObj.upstream) {
await this.repository.fetch({ remote: branchObj.upstream.remote, ref: `${branchObj.upstream.name}:${branchObj.name}` });
try {
await this.repository.fetch({ remote: branchObj.upstream.remote, ref: `${branchObj.upstream.name}:${branchObj.name}` });
} catch (e) {
if (e.stderr?.startsWith && e.stderr.startsWith('fatal: refusing to fetch into branch')) {
// This can happen when there's some state on the "main" branch
// This could be unpushed commits or a bisect for example
vscode.window.showErrorMessage(vscode.l10n.t('Unable to fetch the {0} branch. There is some state (bisect, unpushed commits, etc.) on {0} that is preventing the fetch.', [branchObj.name]));
} else {
throw e;
}
}
}

if (branchObj.upstream && branch === branchObj.upstream.name) {
Expand Down

0 comments on commit a692853

Please sign in to comment.