fix: create strategy branch before first commit, not at execute-phase (#1278)
When branching_strategy is "phase" or "milestone", the branch was only created during execute-phase — but discuss-phase, plan-phase, and new-milestone all commit artifacts before that, landing them on main. Move branch creation into cmdCommit() so the strategy branch is created at the first commit point in any workflow. execute-phase's existing handle_branching step becomes a harmless no-op (checkout existing branch). Also fixes websearch test mocks broken by #1276 (fs.writeSync change). Closes #1278 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -247,6 +247,43 @@ function cmdCommit(cwd, message, files, raw, amend, noVerify) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure branching strategy branch exists before first commit (#1278).
|
||||
// Pre-execution workflows (discuss, plan, research) commit artifacts but the branch
|
||||
// was previously only created during execute-phase — too late.
|
||||
if (config.branching_strategy && config.branching_strategy !== 'none') {
|
||||
let branchName = null;
|
||||
if (config.branching_strategy === 'phase') {
|
||||
// Determine which phase we're committing for from the file paths
|
||||
const phaseMatch = (files || []).join(' ').match(/(\d+)-/);
|
||||
if (phaseMatch) {
|
||||
const phaseNum = phaseMatch[1];
|
||||
const phaseInfo = findPhaseInternal(cwd, phaseNum);
|
||||
if (phaseInfo) {
|
||||
branchName = config.phase_branch_template
|
||||
.replace('{phase}', phaseInfo.phase_number)
|
||||
.replace('{slug}', phaseInfo.phase_slug || 'phase');
|
||||
}
|
||||
}
|
||||
} else if (config.branching_strategy === 'milestone') {
|
||||
const milestone = getMilestoneInfo(cwd);
|
||||
if (milestone && milestone.version) {
|
||||
branchName = config.milestone_branch_template
|
||||
.replace('{milestone}', milestone.version)
|
||||
.replace('{slug}', generateSlugInternal(milestone.name) || 'milestone');
|
||||
}
|
||||
}
|
||||
if (branchName) {
|
||||
const currentBranch = execGit(cwd, ['rev-parse', '--abbrev-ref', 'HEAD']);
|
||||
if (currentBranch.exitCode === 0 && currentBranch.stdout.trim() !== branchName) {
|
||||
// Create branch if it doesn't exist, or switch to it if it does
|
||||
const create = execGit(cwd, ['checkout', '-b', branchName]);
|
||||
if (create.exitCode !== 0) {
|
||||
execGit(cwd, ['checkout', branchName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stage files
|
||||
const filesToStage = files && files.length > 0 ? files : ['.planning/'];
|
||||
for (const file of filesToStage) {
|
||||
|
||||
Reference in New Issue
Block a user