Skip to content

Commit

Permalink
Git - remove hard coded remote name when detecting the default branch (
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored Jan 7, 2025
1 parent e2e9a73 commit cbb7f99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2779,8 +2779,8 @@ export class Repository {
return Promise.reject<Branch>(new Error(`No such branch: ${name}.`));
}

async getDefaultBranch(): Promise<Branch> {
const result = await this.exec(['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']);
async getDefaultBranch(remoteName: string): Promise<Branch> {
const result = await this.exec(['symbolic-ref', '--short', `refs/remotes/${remoteName}/HEAD`]);
if (!result.stdout || result.stderr) {
throw new Error('No default branch');
}
Expand Down
7 changes: 6 additions & 1 deletion extensions/git/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,12 @@ export class Repository implements Disposable {

private async getDefaultBranch(): Promise<Branch | undefined> {
try {
const defaultBranch = await this.repository.getDefaultBranch();
if (this.remotes.length === 0) {
return undefined;
}

const remote = this.remotes.find(r => r.name === 'origin') ?? this.remotes[0];
const defaultBranch = await this.repository.getDefaultBranch(remote.name);
return defaultBranch;
}
catch (err) {
Expand Down

0 comments on commit cbb7f99

Please sign in to comment.