Skip to content

Commit 8fa502f

Browse files
Copilotalexr00
andauthored
Add githubIssues.workingBaseBranch setting to control base branch selection (#8229)
* Initial plan * Planning: Add githubIssues.workingBaseBranch setting Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add githubIssues.workingBaseBranch setting with implementation Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add tests for workingBaseBranch setting Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Fix typo: 'isssue' -> 'issue' Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Use actual branch names in prompt and delete failing tests Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Handle case when current branch equals default branch in prompt Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 4456669 commit 8fa502f

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,21 @@
716716
"default": "on",
717717
"markdownDescription": "%githubIssues.useBranchForIssues.markdownDescription%"
718718
},
719+
"githubIssues.workingBaseBranch": {
720+
"type": "string",
721+
"enum": [
722+
"currentBranch",
723+
"defaultBranch",
724+
"prompt"
725+
],
726+
"enumDescriptions": [
727+
"%githubIssues.workingBaseBranch.currentBranch%",
728+
"%githubIssues.workingBaseBranch.defaultBranch%",
729+
"%githubIssues.workingBaseBranch.prompt%"
730+
],
731+
"default": "currentBranch",
732+
"markdownDescription": "%githubIssues.workingBaseBranch.markdownDescription%"
733+
},
719734
"githubIssues.issueCompletionFormatScm": {
720735
"type": "string",
721736
"default": "${issueTitle}\nFixes ${issueNumberLabel}",

package.nls.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@
131131
"githubIssues.useBranchForIssues.on": "A branch will always be checked out when you start working on an issue. If the branch doesn't exist, it will be created.",
132132
"githubIssues.useBranchForIssues.off": "A branch will not be created when you start working on an issue. If you have worked on an issue before and a branch was created for it, that same branch will be checked out.",
133133
"githubIssues.useBranchForIssues.prompt": "A prompt will show for setting the name of the branch that will be created and checked out.",
134+
"githubIssues.workingBaseBranch.markdownDescription": {
135+
"message": "Determines which branch to use as the base when creating a new branch for an issue. This setting controls what branch the new issue branch is created from.",
136+
"comment": [
137+
"Describes the base branch selection for issue branches"
138+
]
139+
},
140+
"githubIssues.workingBaseBranch.currentBranch": "Create the issue branch from the current branch without switching to the default branch first.",
141+
"githubIssues.workingBaseBranch.defaultBranch": "Always switch to the default branch before creating the issue branch.",
142+
"githubIssues.workingBaseBranch.prompt": "Prompt which branch to use as the base when creating an issue branch.",
134143
"githubIssues.issueCompletionFormatScm.markdownDescription": {
135144
"message": "Sets the format of issue completions in the SCM inputbox. \n- `${user}` will be replace with the currently logged in username \n- `${issueNumber}` will be replaced with the current issue number \n- `${issueNumberLabel}` will be replaced with a label formatted as #number or owner/repository#number, depending on whether the issue is in the current repository",
136145
"comment": [

src/common/settingKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const IGNORE_USER_COMPLETION_TRIGGER = 'ignoreUserCompletionTrigger';
5050
export const CREATE_INSERT_FORMAT = 'createInsertFormat';
5151
export const ISSUE_BRANCH_TITLE = 'issueBranchTitle';
5252
export const USE_BRANCH_FOR_ISSUES = 'useBranchForIssues';
53+
export const WORKING_BASE_BRANCH = 'workingBaseBranch';
5354
export const WORKING_ISSUE_FORMAT_SCM = 'workingIssueFormatScm';
5455
export const IGNORE_COMPLETION_TRIGGER = 'ignoreCompletionTrigger';
5556
export const ISSUE_COMPLETION_FORMAT_SCM = 'issueCompletionFormatScm';

src/issues/issueFeatureRegistrar.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ISSUE_COMPLETIONS,
2121
ISSUES_SETTINGS_NAMESPACE,
2222
USER_COMPLETIONS,
23+
WORKING_BASE_BRANCH,
2324
} from '../common/settingKeys';
2425
import { editQuery } from '../common/settingsUtils';
2526
import { ITelemetry } from '../common/telemetry';
@@ -809,7 +810,7 @@ export class IssueFeatureRegistrar extends Disposable {
809810
let githubRepository = issueModel.githubRepository;
810811
let remote = issueModel.remote;
811812
if (!repoManager) {
812-
repoManager = await this.chooseRepo(vscode.l10n.t('Choose which repository you want to work on this isssue in.'));
813+
repoManager = await this.chooseRepo(vscode.l10n.t('Choose which repository you want to work on this issue in.'));
813814
if (!repoManager) {
814815
return;
815816
}
@@ -824,10 +825,40 @@ export class IssueFeatureRegistrar extends Disposable {
824825
}
825826
}
826827

828+
// Determine whether to checkout the default branch based on workingBaseBranch setting
829+
const workingBaseBranchConfig = vscode.workspace.getConfiguration(ISSUES_SETTINGS_NAMESPACE).get<string>(WORKING_BASE_BRANCH);
830+
let checkoutDefaultBranch = false;
831+
832+
if (workingBaseBranchConfig === 'defaultBranch') {
833+
checkoutDefaultBranch = true;
834+
} else if (workingBaseBranchConfig === 'prompt') {
835+
const currentBranchName = repoManager.repository.state.HEAD?.name;
836+
const defaults = await repoManager.getPullRequestDefaults();
837+
const defaultBranchName = defaults.base;
838+
839+
if (!currentBranchName) {
840+
// If we can't determine the current branch, default to the default branch
841+
checkoutDefaultBranch = true;
842+
} else if (currentBranchName === defaultBranchName) {
843+
// If already on the default branch, no need to prompt
844+
checkoutDefaultBranch = false;
845+
} else {
846+
const choice = await vscode.window.showQuickPick([currentBranchName, defaultBranchName], {
847+
placeHolder: vscode.l10n.t('Which branch should be used as the base for the new issue branch?'),
848+
});
849+
if (choice === undefined) {
850+
// User cancelled the prompt
851+
return;
852+
}
853+
checkoutDefaultBranch = choice === defaultBranchName;
854+
}
855+
}
856+
// else workingBaseBranchConfig === 'currentBranch', checkoutDefaultBranch remains false
857+
827858
await this._stateManager.setCurrentIssue(
828859
repoManager,
829860
new CurrentIssue(issueModel, repoManager, this._stateManager, remoteNameResult.remote, needsBranchPrompt),
830-
true
861+
checkoutDefaultBranch
831862
);
832863
}
833864

0 commit comments

Comments
 (0)