Skip to content

Commit 535f657

Browse files
committed
Scopes PR worktree created branches to pr/
1 parent 67b6b67 commit 535f657

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/commands/ghpr/openOrCreateWorktree.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { Logger } from '../../system/logger';
1212
import { waitUntilNextTick } from '../../system/promise';
1313
import { Command } from '../base';
1414

15-
interface PullRequestNode {
16-
readonly pullRequestModel: PullRequest;
15+
interface GHPRPullRequestNode {
16+
readonly pullRequestModel: GHPRPullRequest;
1717
}
1818

19-
interface PullRequest {
19+
interface GHPRPullRequest {
2020
readonly base: {
2121
readonly repositoryCloneUrl: {
2222
readonly owner: string;
@@ -46,7 +46,7 @@ export class OpenOrCreateWorktreeCommand extends Command {
4646
super(Commands.OpenOrCreateWorktreeForGHPR);
4747
}
4848

49-
async execute(...args: [PullRequestNode | PullRequest, ...unknown[]]) {
49+
async execute(...args: [GHPRPullRequestNode | GHPRPullRequest, ...unknown[]]) {
5050
const [arg] = args;
5151
let pr;
5252
if ('pullRequestModel' in arg) {
@@ -80,9 +80,10 @@ export class OpenOrCreateWorktreeCommand extends Command {
8080
}
8181

8282
const branchName = `${remoteOwner}/${ref}`;
83+
const prBranchName = `pr/${branchName}`;
8384

8485
const worktrees = await repo.getWorktrees();
85-
const worktree = worktrees.find(w => w.branch === branchName);
86+
const worktree = worktrees.find(w => w.branch === branchName || w.branch === prBranchName);
8687
if (worktree != null) {
8788
void openWorktree(worktree);
8889

@@ -121,18 +122,18 @@ export class OpenOrCreateWorktreeCommand extends Command {
121122
repo,
122123
undefined,
123124
createReference(branchName, repo.path, { refType: 'branch', name: branchName, remote: true }),
124-
{ createBranch: branchName },
125+
{ createBranch: prBranchName },
125126
);
126127

127128
// Ensure that the worktree was created
128-
const worktree = await this.container.git.getWorktree(repo.path, w => w.branch === branchName);
129+
const worktree = await this.container.git.getWorktree(repo.path, w => w.branch === prBranchName);
129130
if (worktree == null) return;
130131

131132
// Save the PR number in the branch config
132133
// https://github.com/Microsoft/vscode-pull-request-github/blob/0c556c48c69a3df2f9cf9a45ed2c40909791b8ab/src/github/pullRequestGitHelper.ts#L18
133134
void this.container.git.setConfig(
134135
repo.path,
135-
`branch.${branchName}.github-pr-owner-number`,
136+
`branch.${prBranchName}.github-pr-owner-number`,
136137
`${rootOwner}#${rootRepository}#${number}`,
137138
);
138139
} catch (ex) {

0 commit comments

Comments
 (0)