* Build a self-contained git fixture representing an already-shipped state: * - main branch at VERSION 0.0.1, with one CHANGELOG entry [0.0.1] * - feat/already-shipped branch at VERSION 0.0.2 (bumped + synced), * CHANGELOG has [0.0.2] entry on top of [0.0.1], one feature commit * - bar
()
| 61 | * Returns the work-tree dir for /ship to operate on. |
| 62 | */ |
| 63 | function buildShippedFixture(): ShipFixture { |
| 64 | const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-ship-fixture-')); |
| 65 | const workTree = path.join(root, 'workspace'); |
| 66 | const bareRemote = path.join(root, 'origin.git'); |
| 67 | fs.mkdirSync(workTree, { recursive: true }); |
| 68 | |
| 69 | const setupLog: string[] = []; |
| 70 | const sh = (cmd: string, cwd: string): void => { |
| 71 | setupLog.push(`[${cwd}] ${cmd}`); |
| 72 | const result = spawnSync('bash', ['-c', cmd], { cwd, stdio: 'pipe', timeout: 15_000 }); |
| 73 | if (result.status !== 0) { |
| 74 | const stderr = result.stderr?.toString() ?? ''; |
| 75 | throw new Error(`fixture setup failed at "${cmd}":\n${stderr}\n--- log ---\n${setupLog.join('\n')}`); |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | // Bare remote. |
| 80 | sh(`git init --bare "${bareRemote}"`, root); |
| 81 | |
| 82 | // Initial commit on main. |
| 83 | sh('git init -b main', workTree); |
| 84 | sh('git config user.email "test@test.com"', workTree); |
| 85 | sh('git config user.name "Test"', workTree); |
| 86 | sh('git config commit.gpgsign false', workTree); |
| 87 | |
| 88 | fs.writeFileSync(path.join(workTree, 'VERSION'), '0.0.1\n'); |
| 89 | fs.writeFileSync( |
| 90 | path.join(workTree, 'package.json'), |
| 91 | JSON.stringify({ name: 'fixture', version: '0.0.1', private: true }, null, 2) + '\n', |
| 92 | ); |
| 93 | fs.writeFileSync( |
| 94 | path.join(workTree, 'CHANGELOG.md'), |
| 95 | `# Changelog\n\n## [0.0.1] - 2026-01-01\n\n- Initial release\n`, |
| 96 | ); |
| 97 | fs.writeFileSync(path.join(workTree, 'README.md'), '# Fixture\n'); |
| 98 | |
| 99 | sh('git add VERSION package.json CHANGELOG.md README.md', workTree); |
| 100 | sh('git commit -m "chore: initial release v0.0.1"', workTree); |
| 101 | sh(`git remote add origin "${bareRemote}"`, workTree); |
| 102 | sh('git push -u origin main', workTree); |
| 103 | |
| 104 | // Feature branch with ALREADY_BUMPED state. |
| 105 | sh('git checkout -b feat/already-shipped', workTree); |
| 106 | fs.writeFileSync(path.join(workTree, 'VERSION'), '0.0.2\n'); |
| 107 | fs.writeFileSync( |
| 108 | path.join(workTree, 'package.json'), |
| 109 | JSON.stringify({ name: 'fixture', version: '0.0.2', private: true }, null, 2) + '\n', |
| 110 | ); |
| 111 | fs.writeFileSync( |
| 112 | path.join(workTree, 'CHANGELOG.md'), |
| 113 | `# Changelog\n\n## [0.0.2] - 2026-04-25\n\n**Feature shipped.**\n\nAdded the new feature.\n\n## [0.0.1] - 2026-01-01\n\n- Initial release\n`, |
| 114 | ); |
| 115 | fs.writeFileSync(path.join(workTree, 'feature.md'), '# Feature\n\nAlready shipped.\n'); |
| 116 | |
| 117 | sh('git add VERSION package.json CHANGELOG.md feature.md', workTree); |
| 118 | sh('git commit -m "feat: add new feature\n\nbumps VERSION to 0.0.2"', workTree); |
| 119 | sh('git push -u origin feat/already-shipped', workTree); |
| 120 |
no test coverage detected