Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
/ship catches a file-mode change from main on files whose names start with a colon (#4774)
Garry Tan6b7714c3e85e
diff --git a/changelog.d/ls-tree-mode-check-fails-closed.md b/changelog.d/ls-tree-mode-check-fails-closed.mdnew file mode 100644index 000000000..663b85dd9--- /dev/null+++ b/changelog.d/ls-tree-mode-check-fails-closed.md@@ -0,0 +1 @@+**/ship no longer misses a file-mode change from main on files whose names start with `:`.** A name like `:!tool.sh` or `:(glob)tool.sh` made git refuse /ship's mode lookup on both heads, and the two failures compared as equal, and a name like `:(top)tool.sh` read the mode of a different file, so a merged head could count as reviewed after main changed such a file's mode. Both mode lookups now read the name literally, and a lookup that fails counts as a change that needs review.diff --git a/lib/ship-patch.ts b/lib/ship-patch.tsindex 40915816b..7ac5bcb4b 100644--- a/lib/ship-patch.ts+++ b/lib/ship-patch.ts@@ -192,8 +192,8 @@ export function comparePath(repoRoot: string, s: PatchSides, rel: string): PathVspliced = true;}if (ids[0] === ids[1] && !spliced) return 'same';- const mode = (ref: string) => git(repoRoot, ['ls-tree', '--full-tree', ref, '--', rel])?.split(' ')[0];- if (mode(s.reviewed) !== mode(s.current)) return 'changed';+ const [rm, cm] = [s.reviewed, s.current].map(ref => git(repoRoot, ['--literal-pathspecs', 'ls-tree', '--full-tree', ref, '--', rel]));+ if (rm == null || cm == null || rm.split(' ')[0] !== cm.split(' ')[0]) return 'changed';return spliced ? 'spliced' : 'context';} finally {sides.done();@@ -244,7 +244,7 @@ export function baseHolds(repoRoot: string, s: PatchSides, rel: string): booleanreturn r.status === 0 ? r.stdout : null;});if (blobs.some(b => b === null)) return false;- const [mc, mb, mr] = [s.currentBase, s.reviewedBase, s.reviewed].map(ref => git(repoRoot, ['ls-tree', '--full-tree', ref, '--', rel])?.split(' ')[0]);+ const [mc, mb, mr] = [s.currentBase, s.reviewedBase, s.reviewed].map(ref => git(repoRoot, ['--literal-pathspecs', 'ls-tree', '--full-tree', ref, '--', rel])?.split(' ')[0]);if (!mc || !mr || (mr !== mb && mr !== mc)) return false;const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ship-patch-'));try {diff --git a/test/ship-base-side-masks.test.ts b/test/ship-base-side-masks.test.tsindex 5fa74741e..e039b46f9 100644--- a/test/ship-base-side-masks.test.ts+++ b/test/ship-base-side-masks.test.ts@@ -9,7 +9,7 @@ import { afterEach, describe, expect, setDefaultTimeout, test } from 'bun:test';import * as fs from 'node:fs';import * as path from 'node:path';import { EXIT } from '../lib/headless-artifacts';-import { comparePath } from '../lib/ship-patch';+import { baseHolds, comparePath } from '../lib/ship-patch';import { extractReceipt, placeReceipt } from '../lib/ship-receipt';import { lineOf, RELEASE, shipFixture, type ShipFx } from './helpers/ship-bin-fixture';@@ -220,21 +220,22 @@ describe('a base merge counts as reviewed only when the branch\'s own lines, moddescribe('a merge that chose its own order, a base mode flip, or bytes that are not UTF-8 never count as reviewed (GST-3562 G)', () => {const P = 'src/tool.sh';/** Four sides in one repository: A, the reviewed branch R on A, the base B on A, and the merge C of R and B with `resolved`. */- const sides = (base: string | Buffer, reviewed: string | Buffer, baseSide: string | Buffer, resolved: string | Buffer, baseExec = false) => {+ const sides = (base: string | Buffer, reviewed: string | Buffer, baseSide: string | Buffer, resolved: string | Buffer, baseExec = false, p = P) => {const f = fx();- const put = (text: string | Buffer) => fs.writeFileSync(path.join(f.work, P), text);+ const put = (text: string | Buffer) => fs.writeFileSync(path.join(f.work, p), text);fs.mkdirSync(path.join(f.work, 'src'), { recursive: true });+ fs.writeFileSync(path.join(f.work, 'tool.sh'), 'echo top\n'); fs.chmodSync(path.join(f.work, 'tool.sh'), 0o755);put(base); f.commit('A');const A = f.git('rev-parse', 'HEAD').stdout.trim();put(reviewed); f.commit('R');const R = f.git('rev-parse', 'HEAD').stdout.trim();f.git('checkout', '-q', '-b', 'side', A);- put(baseSide); if (baseExec) fs.chmodSync(path.join(f.work, P), 0o755); f.commit('B');+ put(baseSide); if (baseExec) fs.chmodSync(path.join(f.work, p), 0o755); f.commit('B');const B = f.git('rev-parse', 'HEAD').stdout.trim();f.git('checkout', '-q', '-b', 'merged', R);f.git('merge', '-q', '--no-commit', '--no-edit', B);- put(resolved); if (baseExec) fs.chmodSync(path.join(f.work, P), 0o755); f.commit('C');- return comparePath(f.work, { reviewedBase: A, reviewed: R, currentBase: B, current: f.git('rev-parse', 'HEAD').stdout.trim() }, P);+ put(resolved); if (baseExec) fs.chmodSync(path.join(f.work, p), 0o755); f.commit('C');+ return comparePath(f.work, { reviewedBase: A, reviewed: R, currentBase: B, current: f.git('rev-parse', 'HEAD').stdout.trim() }, p);};const at = (edit: Record<number, string[]>) => rows().trimEnd().split('\n').flatMap((l, i) => [edit[i + 1]?.[0] ?? l, ...(edit[i + 1]?.slice(1) ?? [])]).join('\n') + '\n';const GUARD = 'export const guard = 1;';@@ -258,4 +259,30 @@ describe('a merge that chose its own order, a base mode flip, or bytes that areexpect(sides(rows(), latin(0xe9), rows({ 5: 'export const r5 = 50;' }), latin(0xe8, 'r5 = 50'))).toBe('changed');expect(sides(rows(), plain, rows({ 5: 'export const r5 = 50;' }), rows({ 5: 'export const r5 = 50;', 6: 'export const r6 = "cafe";' }))).toBe('context');});++ // Value: protects=no review is lost by G when a file name starts with pathspec magic, which git ls-tree rejects unless told+ // to read it literally, so both mode lookups failed and compared equal, or resolves to another file (`:(top)tool.sh` read+ // the executable root tool.sh); fails_when=the base exec-bit flip on such a file compares as context, the control without+ // a flip stops being context, or baseHolds holds a reviewed mode change the base dropped; seam=comparePath, baseHolds;+ // no_claim=Windows, where the name is not a legal file name+ test.skipIf(process.platform === 'win32')('a base exec-bit flip on a file whose name starts with pathspec magic is changed', () => {+ for (const name of [':!tool.sh', ':(glob)tool.sh', ':(top)tool.sh']) {+ expect(sides(rows(), rows(OWN), rows({ 5: 'export const r5 = 50;' }), rows({ 5: 'export const r5 = 50;', ...OWN }), true, name)).toBe('changed');+ expect(sides(rows(), rows(OWN), rows({ 5: 'export const r5 = 50;' }), rows({ 5: 'export const r5 = 50;', ...OWN }), false, name)).toBe('context');+ }+ const f = fx();+ const [top, magic] = [path.join(f.work, 'tool.sh'), path.join(f.work, ':(top)tool.sh')];+ fs.writeFileSync(top, 'echo top\n'); fs.chmodSync(top, 0o755);+ fs.writeFileSync(magic, 'echo a\n'); f.commit('A');+ const A = f.git('rev-parse', 'HEAD').stdout.trim();+ fs.writeFileSync(magic, 'echo b\n'); fs.chmodSync(magic, 0o755); f.commit('R');+ const R = f.git('rev-parse', 'HEAD').stdout.trim();+ const base = (exec: boolean) => {+ f.git('checkout', '-q', '-B', exec ? 'took-mode' : 'took-content', A);+ fs.writeFileSync(magic, 'echo b\n'); fs.chmodSync(magic, exec ? 0o755 : 0o644); f.commit('B');+ return baseHolds(f.work, { reviewedBase: A, reviewed: R, currentBase: f.git('rev-parse', 'HEAD').stdout.trim(), current: R }, ':(top)tool.sh');+ };+ expect(base(false)).toBe(false);+ expect(base(true)).toBe(true);+ });});