Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(worktree): a lockfile is committed only when HEAD has it [I1,L3]
Corey Olson9da23d22bb2f
diff --git a/src/worktree.js b/src/worktree.jsindex 1191163d..f91d351e 100644--- a/src/worktree.js+++ b/src/worktree.js@@ -24,16 +24,17 @@ function declaredDependencies(root) {}/**- * Name the npm lockfile git tracks in `root`, or null when none is committed.+ * Name the npm lockfile the checkout's HEAD commit holds, or null when none is committed.*- * A lockfile counts only when git tracks it: one that merely sits on disk is what an earlier- * install wrote, and `npm ci` from it would install something the commit does not record.+ * A lockfile counts only when HEAD has it: one that sits on disk or is only staged (a hook can+ * stage one in a new worktree) is not in the commit, and `npm ci` from it would install+ * something the commit does not record.** @param {string} root* @returns {string | null}*/function committedLockfile(root) {- const listed = tryGit(root, ['ls-files', '-z', '--', ...NPM_LOCKFILES], { env: cleanGitEnvironment() });+ const listed = tryGit(root, ['ls-tree', '-z', '--name-only', 'HEAD', '--', ...NPM_LOCKFILES], { env: cleanGitEnvironment() });if (listed.status !== 0) return null;const tracked = new Set(listed.stdout.split('\0').filter(Boolean));return NPM_LOCKFILES.find((name) => tracked.has(name)) ?? null;diff --git a/test/worktree-start.test.js b/test/worktree-start.test.jsindex 7152798e..c21f683e 100644--- a/test/worktree-start.test.js+++ b/test/worktree-start.test.js@@ -233,7 +233,7 @@ test('worktree suggests no install for a zero-dependency project [I1,L3]', () =>'without a committed lockfile the step is npm install, with the lockfile it writes named for commit');assert.doesNotMatch(unlocked, /\bnpm ci\b/u, 'npm ci fails without a lockfile');- // A lockfile on disk that git does not track is not committed; a tracked shrinkwrap is.+ // A lockfile on disk or only staged is not committed; one HEAD holds is.const loose = join(box.dir, 'loose');mkdirSync(loose);box.git(loose, 'init', '-q', '-b', 'main');@@ -244,6 +244,8 @@ test('worktree suggests no install for a zero-dependency project [I1,L3]', () =>assert.equal(installStep(loose)?.command, 'npm install', 'an untracked package-lock.json does not count as committed');writeFileSync(join(loose, 'npm-shrinkwrap.json'), '{}');box.git(loose, 'add', 'npm-shrinkwrap.json');+ assert.equal(installStep(loose)?.command, 'npm install', 'a staged npm-shrinkwrap.json that HEAD lacks does not count as committed');+ box.git(loose, 'commit', '-q', '-m', 'chore: shrinkwrap');assert.deepEqual(installStep(loose), { command: 'npm ci', note: 'its own install from the committed npm-shrinkwrap.json, so its tests run its own code' },- 'a tracked npm-shrinkwrap.json is a committed lockfile');+ 'an npm-shrinkwrap.json in HEAD is a committed lockfile');});