Skip to content

Commit fab1204

Browse files
Copilotalexr00
andcommitted
fix: address code review feedback - improve error handling and branch naming
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent ecc650d commit fab1204

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/commands.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,9 @@ export function registerCommands(
847847
return vscode.window.showErrorMessage(vscode.l10n.t('Unable to checkout pull request: missing head branch information.'));
848848
}
849849

850+
// Store validated head to avoid non-null assertions later
851+
const prHead = pullRequestModel.head;
852+
850853
// Get the folder manager to access the repository
851854
const folderManager = reposManager.getManagerForIssueModel(pullRequestModel);
852855
if (!folderManager) {
@@ -867,15 +870,16 @@ export function registerCommands(
867870
},
868871
async (progress) => {
869872
// Generate a branch name for the worktree
870-
const branchName = pullRequestModel.head!.ref;
873+
const branchName = prHead.ref;
871874
const remoteName = pullRequestModel.remote.remoteName;
872875

873876
// Fetch the PR branch first
874877
progress.report({ message: vscode.l10n.t('Fetching branch {0}...', branchName) });
875878
try {
876879
await repositoryToUse.fetch({ remote: remoteName, ref: branchName });
877880
} catch (e) {
878-
Logger.appendLine(`Failed to fetch branch ${branchName}: ${e}`, logId);
881+
const errorMessage = e instanceof Error ? e.message : String(e);
882+
Logger.appendLine(`Failed to fetch branch ${branchName}: ${errorMessage}`, logId);
879883
// Continue even if fetch fails - the branch might already be available locally
880884
}
881885

@@ -900,7 +904,7 @@ export function registerCommands(
900904
progress.report({ message: vscode.l10n.t('Creating worktree at {0}...', worktreePath) });
901905

902906
const trackedBranchName = `${remoteName}/${branchName}`;
903-
const localBranchName = `pr-${pullRequestModel.number}/${branchName}`;
907+
const localBranchName = `pr-${pullRequestModel.number}-${branchName}`;
904908

905909
try {
906910
// Create a VS Code task to execute the git worktree command

0 commit comments

Comments
 (0)