Skip to content

Commit 6f7fc11

Browse files
committed
Fixes default branch lookup
1 parent 3efa4f2 commit 6f7fc11

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/git/gitService.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,26 +1654,15 @@ export class GitService implements Disposable {
16541654

16551655
remote = remote ?? 'origin';
16561656
try {
1657-
const data = await Git.symbolic_ref(repoPath, `refs/remotes/${remote}/HEAD`);
1657+
const data = await Git.ls_remote__HEAD(repoPath, remote);
16581658
if (data == null) return undefined;
16591659

1660-
return data.trim().substr(`${remote}/`.length);
1661-
} catch (ex) {
1662-
if (/is not a symbolic ref/.test(ex.stderr)) {
1663-
try {
1664-
const data = await Git.ls_remote__HEAD(repoPath, remote);
1665-
if (data == null) return undefined;
1666-
1667-
const match = /ref:\s(\S+)\s+HEAD/m.exec(data);
1668-
if (match == null) return undefined;
1669-
1670-
const [, branch] = match;
1671-
return branch.substr('refs/heads/'.length);
1672-
} catch {
1673-
return undefined;
1674-
}
1675-
}
1660+
const match = /ref:\s(\S+)\s+HEAD/m.exec(data);
1661+
if (match == null) return undefined;
16761662

1663+
const [, branch] = match;
1664+
return branch.substr('refs/heads/'.length);
1665+
} catch {
16771666
return undefined;
16781667
}
16791668
}

src/quickpicks/remoteProviderPicker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ export class CopyOrOpenRemoteCommandQuickPickItem extends CommandQuickPickItem {
5050
}
5151
} else if (resource.type === RemoteResourceType.CreatePullRequest) {
5252
let branch = resource.base.branch;
53-
if (branch == null && this.remote.provider.hasApi()) {
54-
const defaultBranch = await this.remote.provider.getDefaultBranch?.();
55-
branch = defaultBranch?.name;
53+
if (branch == null) {
54+
branch = await Container.git.getDefaultBranchName(this.remote.repoPath, this.remote.name);
55+
if (branch == null && this.remote.provider.hasApi()) {
56+
const defaultBranch = await this.remote.provider.getDefaultBranch?.();
57+
branch = defaultBranch?.name;
58+
}
5659
}
5760

5861
resource = {

0 commit comments

Comments
 (0)