Skip to content

Commit a692853

Browse files
authored
Better error message when we can't fetch the default branch (#6655)
1 parent 9c60049 commit a692853

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/github/folderRepositoryManager.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,17 @@ export class FolderRepositoryManager extends Disposable {
24242424

24252425
// respect the git setting to fetch before checkout
24262426
if (vscode.workspace.getConfiguration(GIT).get<boolean>(PULL_BEFORE_CHECKOUT, false) && branchObj.upstream) {
2427-
await this.repository.fetch({ remote: branchObj.upstream.remote, ref: `${branchObj.upstream.name}:${branchObj.name}` });
2427+
try {
2428+
await this.repository.fetch({ remote: branchObj.upstream.remote, ref: `${branchObj.upstream.name}:${branchObj.name}` });
2429+
} catch (e) {
2430+
if (e.stderr?.startsWith && e.stderr.startsWith('fatal: refusing to fetch into branch')) {
2431+
// This can happen when there's some state on the "main" branch
2432+
// This could be unpushed commits or a bisect for example
2433+
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]));
2434+
} else {
2435+
throw e;
2436+
}
2437+
}
24282438
}
24292439

24302440
if (branchObj.upstream && branch === branchObj.upstream.name) {

0 commit comments

Comments
 (0)