Skip to content

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.

fix(core): name broken bare checkout [A6,P4]

Corey Olsone9d37c9681b3
diff --git a/src/cli.js b/src/cli.js
index 3e43bb61..acbf83d6 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -11,7 +11,7 @@ import * as store from './board.js';
import { CONFIG_FILE, COORDINATOR, loadConfig } from './config.js';
import { loadDoctrine } from './doctrine.js';
import { digestOf, gateReport, runGate, runShell } from './gate.js';
-import { contains, differFromHead, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';
+import { bareWorktreeFinding, contains, differFromHead, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';
import {
FIX_NOTE,
applyFixers,
@@ -990,6 +990,13 @@ function readCommands(io, { first, second, rest, values }) {
return 0;
},
doctor: () => {
+ const bare = bareWorktreeFinding(io.cwd);
+ if (bare) {
+ const problems = [bare];
+ io.result?.({ problems });
+ for (const problem of problems) io.say(`problem: ${problem.message}; repair: ${problem.next}`);
+ return 1;
+ }
const ctx = context(io);
const problems = doctorProblems(ctx.file, ctx.info.root, tryGit);
io.result?.({ problems });
diff --git a/src/git.js b/src/git.js
index f1bacd7b..bbc75048 100644
--- a/src/git.js
+++ b/src/git.js
@@ -3,7 +3,8 @@
* and whether the tree is clean. Every call is a plain `git` child process.
*/
import { execFileSync, spawnSync } from 'node:child_process';
-import { resolve } from 'node:path';
+import { existsSync, readdirSync, statSync } from 'node:fs';
+import { dirname, join, resolve } from 'node:path';
import { Refused } from './refused.js';
const GIT_FLAGS = ['-c', 'core.quotepath=false'];
@@ -49,6 +50,43 @@ export function tryGit(cwd, args) {
return { status: result.status ?? 1, stdout: (result.stdout ?? '').trim() };
}
+/**
+ * Find a main checkout whose `.git/config` marks it bare despite files beside its git directory.
+ * This check uses the filesystem and explicit config path so inherited Git repository variables
+ * cannot hide a damaged checkout from the command that needs to explain its repair.
+ *
+ * @param {string} cwd
+ * @returns {{ code: string, message: string, next: string } | null}
+ */
+export function bareWorktreeFinding(cwd) {
+ let root = resolve(cwd);
+ while (true) {
+ const gitDir = join(root, '.git');
+ if (existsSync(gitDir)) {
+ try {
+ if (!statSync(gitDir).isDirectory()) return null;
+ if (readdirSync(root).some((entry) => entry !== '.git')) {
+ const bare = tryGit(root, ['config', '--file', join(gitDir, 'config'), '--bool', '--get', 'core.bare']);
+ if (bare.status === 0 && bare.stdout === 'true') {
+ const quotedGitDir = `'${gitDir.replaceAll("'", "'\\''")}'`;
+ return {
+ code: 'CORE_BARE',
+ message: `main checkout ${root} has .git/config core.bare=true while working files are present beside .git`,
+ next: `git --git-dir=${quotedGitDir} config core.bare false`,
+ };
+ }
+ }
+ } catch {
+ // An unreadable nearest git directory cannot establish that this is the broken checkout.
+ }
+ return null;
+ }
+ const parent = dirname(root);
+ if (parent === root) return null;
+ root = parent;
+ }
+}
+
/**
* The repo around `cwd`: its worktree root, the shared git dir, this worktree's git dir, and
* whether this is the main checkout.
@@ -61,6 +99,8 @@ export function tryGit(cwd, args) {
export function repoInfo(cwd) {
const top = tryGit(cwd, ['rev-parse', '--show-toplevel']);
if (top.status !== 0) {
+ const bare = bareWorktreeFinding(cwd);
+ if (bare) throw new Refused(bare.code, `${bare.message}; run ${bare.next}`);
throw new Refused('NOT_A_REPO', 'not inside a git work tree; run git init, or cd into a repo');
}
const root = top.stdout;
diff --git a/test/doctor.test.js b/test/doctor.test.js
index b27758b1..b02cc321 100644
--- a/test/doctor.test.js
+++ b/test/doctor.test.js
@@ -18,13 +18,14 @@ after(() => {
/**
* Create a committed repo with a board and isolated git identity for one integrity scenario.
*/
-function boardBox({ initialize = true } = {}) {
+function boardBox({ initialize = true, repoName = 'repo' } = {}) {
const dir = mkdtempSync(join(tmpdir(), 'pullboard-doctor-'));
sandboxes.push(dir);
- const root = join(dir, 'repo');
+ const root = join(dir, repoName);
mkdirSync(root);
- const env = {
- ...process.env,
+ const env = { ...process.env };
+ for (const name of Object.keys(env)) if (name.startsWith('GIT_')) delete env[name];
+ Object.assign(env, {
PULLBOARD_HOME: join(dir, 'home'),
GIT_CONFIG_GLOBAL: '/dev/null',
GIT_CONFIG_NOSYSTEM: '1',
@@ -32,7 +33,7 @@ function boardBox({ initialize = true } = {}) {
GIT_AUTHOR_EMAIL: '[email protected]',
GIT_COMMITTER_NAME: 'Doctor Test',
GIT_COMMITTER_EMAIL: '[email protected]',
- };
+ });
const git = (...args) => execFileSync('git', args, { cwd: root, env, encoding: 'utf8' }).trim();
const run = (...args) => spawnSync(process.execPath, [BIN, ...args], { cwd: root, env, encoding: 'utf8' });
git('init', '-q', '-b', 'main');
@@ -80,6 +81,49 @@ test('doctor reports a clean board in one line and leaves it unchanged [A6]', ()
assert.deepEqual(readFileSync(box.dbFile), before);
});
+test('commands and doctor explain how to repair core.bare without crossing a nested repo [A6, P4]', () => {
+ const box = boardBox({ repoName: "O'Brien project" });
+ const root = box.git('rev-parse', '--show-toplevel');
+ const gitDir = `'${join(root, '.git').replaceAll("'", "'\\''")}'`;
+ const repair = `git --git-dir=${gitDir} config core.bare false`;
+ box.git('config', 'core.bare', 'true');
+
+ const command = box.run('status');
+ assert.equal(command.status, 1);
+ assert.match(command.stderr, /\[CORE_BARE\].*core\.bare=true.*working files are present beside \.git/u);
+ assert.ok(command.stderr.includes(repair), command.stderr);
+ const refusal = box.run('status', '--json');
+ assert.equal(refusal.status, 1);
+ assert.equal(JSON.parse(refusal.stdout).error.next, `run ${repair}`);
+
+ const doctor = box.run('doctor', '--json');
+ assert.equal(doctor.status, 1);
+ assert.equal(doctor.stderr, '');
+ const document = JSON.parse(doctor.stdout);
+ assert.equal(document.version, 1);
+ assert.deepEqual(document.problems, [{
+ code: 'CORE_BARE',
+ message: `main checkout ${root} has .git/config core.bare=true while working files are present beside .git`,
+ next: repair,
+ }]);
+
+ const nested = join(box.root, 'nested');
+ mkdirSync(nested);
+ execFileSync('git', ['init', '-q', '-b', 'main'], { cwd: nested, env: box.env });
+ /** Run the private Pullboard CLI from the nested repo under the bare parent. */
+ const nestedRun = (...args) => spawnSync(process.execPath, [BIN, ...args], { cwd: nested, env: box.env, encoding: 'utf8' });
+ const nestedInit = nestedRun('init');
+ assert.equal(nestedInit.status, 0, nestedInit.stderr);
+ const nestedStatus = nestedRun('status');
+ assert.equal(nestedStatus.status, 0, nestedStatus.stderr);
+ const nestedDoctor = nestedRun('doctor');
+ assert.equal(nestedDoctor.status, 0, nestedDoctor.stderr);
+
+ execFileSync('sh', ['-c', repair], { cwd: root, env: box.env });
+ assert.equal(box.run('status').status, 0);
+ assert.equal(box.run('doctor').status, 0);
+});
+
test('doctor finds a missing lifecycle trigger without reinstalling it [A6]', () => {
const box = boardBox();
mutate(box, (db) => db.exec('DROP TRIGGER machine_item_start'));