Git - remove hard coded remote name when detecting the default branch (#237423)
parent
e2e9a7306b
commit
cbb7f99ba8
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue