-
Notifications
You must be signed in to change notification settings - Fork 588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance Branch Creation UX and Refactor Issue Branch Management #6278
base: main
Are you sure you want to change the base?
Enhance Branch Creation UX and Refactor Issue Branch Management #6278
Conversation
- Implemented a `QuickPick` menu for smoother branch selection and creation process. - Highlighted suggested branch names with visual cues for better user experience. - Enhanced handling of remote branches, ensuring upstream is set automatically when needed. - Removed unnecessary methods (`offerNewBranch`, `getBranchTitle`) to simplify code and improve maintainability. - Improved branch name validation and error messages to provide more helpful feedback.
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cxc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ujghm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! It looks like there are a lot of changes in here that aren't strictly related to the feature you're adding, which makes it slow to review. Could you please remove these changes? I've also left a few other comments.
- Refactored getBranchTitle() to correctly apply the ISSUE_BRANCH_TITLE setting by using variableSubstitution(). - Improved handling of the silent flag. - Cleaned up unrelated code changes.
@alexr00 Thanks for the feedback! I’ve addressed the specific comments and focused on ensuring the necessary changes related to the feature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amrshadid, thanks for your patience! I've left some suggestions and comments.
@@ -130,19 +129,30 @@ export class CurrentIssue extends Disposable { | |||
return undefined; | |||
} | |||
|
|||
private async createOrCheckoutBranch(branch: string): Promise<boolean> { | |||
private async createOrCheckoutBranch(branch: string, silent: boolean): Promise<boolean> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really need a silent
? It seems like something that would always be useful to know if it failed.
private showBranchNameError(error: string) { | ||
const editSetting = `Edit Setting`; | ||
vscode.window.showErrorMessage(error, editSetting).then(result => { | ||
private showBranchNameError(error: string, silent: boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this. I think if the branch name is bad then we should always show an error.
@@ -130,19 +129,30 @@ export class CurrentIssue extends Disposable { | |||
return undefined; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking that the branch name starts with origin/
isn't enough, as not all remotes will be named origin
.
private getRemoteBranchPrefix(branch: string): string | undefined { | |
const remote = this.manager.repository.state.remotes.find((remote) => { | |
return branch.startsWith(`${remote.name}/`); | |
}); | |
return remote ? `${remote.name}/` : undefined; | |
} | |
const isRemoteBranch = branch.startsWith('origin/'); | ||
if (isRemoteBranch) { | ||
localBranchName = branch.substring('origin/'.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isRemoteBranch = branch.startsWith('origin/'); | |
if (isRemoteBranch) { | |
localBranchName = branch.substring('origin/'.length); | |
const remoteBranchPrefix = this.getRemoteBranchPrefix(branch); | |
if (remoteBranchPrefix) { | |
localBranchName = branch.substring(remoteBranchPrefix.length); |
const localBranch = await this.getBranch(localBranchName); | ||
if (localBranch) { | ||
await this.manager.repository.checkout(localBranchName); | ||
} else if (isRemoteBranch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (isRemoteBranch) { | |
} else if (remoteBranchPrefix) { |
); | ||
|
||
// Show QuickPick for branch selection | ||
const quickPick = vscode.window.createQuickPick<vscode.QuickPickItem>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just use showQuickPick
here instead of the more complicated createQuickPick
?
|
||
// Create QuickPick items | ||
const branchItems: vscode.QuickPickItem[] = [ | ||
{ label: 'Suggested branch', kind: vscode.QuickPickItemKind.Separator }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the strings should be localized with vscode.l10n.t
|
||
branchItems.push( | ||
{ label: 'Custom branch name:', kind: vscode.QuickPickItemKind.Separator }, | ||
{ label: '$(pencil) Enter a custom branch name...', description: 'Choose this to type your own branch name' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this string is used again further down, it would be better to move it into a const
, especially after it's been localized.
|
||
this._branchName = customBranchName.trim(); | ||
} else { | ||
this._branchName = selectedBranch.label.replace(/^\$\([^\)]+\)\s*/, '').trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of futzing with the label after the branch has been picked, you can extend QuickPickItem
and add a new property to it to track the actual branch name associated with the quick pick item.
{ label: '$(pencil) Enter a custom branch name...', description: 'Choose this to type your own branch name' } | ||
); | ||
|
||
// Show QuickPick for branch selection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only show the quick pick if createBranchConfig === 'prompt
.
This PR introduces significant improvements to the branch creation and management process, focusing on enhancing the user experience and refactoring the existing code for better maintainability and performance. Key changes include:
Branch Selection UI Overhaul:
Some Related Issues:
These issues are addressed by improving the branch selection experience, handling remote branches more seamlessly, and enhancing error feedback.
Testing and Verification:
Manual Testing: