- 1.1 Create
src/utils/git-utils.tswithisGitRepository(cwd: string): booleanfunction usingexecFileSync('git', ['rev-parse', '--git-dir'], { cwd, stdio: 'pipe' }) - 1.2 Add
createAndCheckoutBranch(cwd: string, branchName: string): voidfunction tosrc/utils/git-utils.tsthat runsgit checkout -b <branchName>viaexecFileSync - 1.3 Add
getBranchNameForChange(changeName: string): stringhelper that returnsopenspec/<changeName> - 1.4 Export all new functions from
src/utils/git-utils.ts
- 2.1 Add
branch?: booleantoNewChangeOptionsinterface insrc/commands/workflow/new-change.ts - 2.2 After successful change creation, check
options.branchand if truthy call git utility functions - 2.3 Show spinner step for git branch creation (e.g., "Creating branch 'openspec/my-feature'...")
- 2.4 On git failure (not a git repo, branch exists, git not found), show warning via
ora().warn()and exit with code 1
- 3.1 Add
.option('--branch', 'Create and checkout a git branch named openspec/<change-name>')to thenew changecommand insrc/cli/index.ts - 3.2 Pass
branchoption through tonewChangeCommandcall
- 4.1 Create
test/core/commands/new-change-git-branch.test.tswith unit tests forisGitRepository,createAndCheckoutBranch, andgetBranchNameForChangeusing mockedexecFileSync - 4.2 Test:
isGitRepositoryreturns true when git command succeeds - 4.3 Test:
isGitRepositoryreturns false when git command throws (not a git repo or git not found) - 4.4 Test:
getBranchNameForChange('my-feature')returns'openspec/my-feature' - 4.5 Test:
createAndCheckoutBranchcallsexecFileSyncwith correct args['checkout', '-b', 'openspec/my-feature'] - 4.6 Test:
newChangeCommandwith--branchcalls git utilities when change creation succeeds - 4.7 Test:
newChangeCommandwith--branchexits nonzero when not in git repo (but change dir is still created) - 4.8 Test:
newChangeCommandwithout--branchnever calls git utilities
- 5.1 Run
pnpm buildand ensure no TypeScript errors - 5.2 Run
pnpm testand ensure all tests pass - 5.3 Manually test:
openspec new change test-branch-feature --branchcreates the branch and checks it out - 5.4 Verify with
git branchthatopenspec/test-branch-featureis the current branch - 5.5 Clean up test branch:
git checkout main && git branch -D openspec/test-branch-feature - 5.6 Delete the test change:
rm -rf openspec/changes/test-branch-feature