Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve index bytes during checkout archival
[._.]/ Adam Eivyd4e897c5a93d
diff --git a/server/services/heldCheckoutRecovery.js b/server/services/heldCheckoutRecovery.jsindex 9128bbbf13..941610a541 100644--- a/server/services/heldCheckoutRecovery.js+++ b/server/services/heldCheckoutRecovery.js@@ -131,9 +131,12 @@ async function snapshotContent(path) {git(['ls-files', '-u', '-z'], path),git(['ls-files', '--stage', '-z'], path),git(['ls-files', '-v', '-z'], path),- // A textconv or external diff driver can drop bytes from a patch.- git(['diff', '--cached', '--binary', '--no-textconv', '--no-ext-diff'], path),- git(['diff', '--binary', '--no-textconv', '--no-ext-diff'], path),+ // A textconv or external diff driver can drop bytes from a patch. Disable+ // diff's stat-cache refresh too: an otherwise read-only diff can rewrite+ // the index and race the concurrent administration snapshot. Git's+ // --no-optional-locks alone does not disable diff.autoRefreshIndex.+ git(['-c', 'diff.autoRefreshIndex=false', 'diff', '--cached', '--binary', '--no-textconv', '--no-ext-diff'], path),+ git(['-c', 'diff.autoRefreshIndex=false', 'diff', '--binary', '--no-textconv', '--no-ext-diff'], path),git(['rev-parse', '--show-object-format'], path),git(['ls-files', '--others', '-z'], path),]);diff --git a/server/services/heldCheckoutRecovery.test.js b/server/services/heldCheckoutRecovery.test.jsindex da8f2098b5..c1f79756cb 100644--- a/server/services/heldCheckoutRecovery.test.js+++ b/server/services/heldCheckoutRecovery.test.js@@ -5,7 +5,7 @@* its lock and its branch as found.*/import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';-import { mkdtemp, mkdir, rm, writeFile, readFile, readdir, symlink } from 'fs/promises';+import { mkdtemp, mkdir, rm, writeFile, readFile, readdir, symlink, utimes } from 'fs/promises';import { existsSync, realpathSync } from 'fs';import { tmpdir } from 'os';import { join } from 'path';@@ -96,7 +96,8 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()it('archives staged, unstaged, untracked, ignored and symlinked content, then retires a locked detached checkout', async () => {await writeFile(join(repo, 'eol.txt'), 'one\ntwo\n');- await execGit(['add', 'eol.txt'], repo);+ await writeFile(join(repo, 'stat-cache.txt'), 'unchanged\n');+ await execGit(['add', 'eol.txt', 'stat-cache.txt'], repo);await execGit(['commit', '-m', 'chore: synthetic text file'], repo);const { path, release } = await heldCheckout('detached-held', { beforeLock: async (tree) => {// Normalization hides these CRLF bytes from every diff.@@ -108,13 +109,19 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()await execGit(['add', 'staged-only.txt'], path);await rm(join(path, 'staged-only.txt'));+ // Make an unchanged tracked file's stat cache stale. Git diff normally+ // rewrites the index while refreshing it, racing the administration copy.+ await utimes(join(path, 'stat-cache.txt'), new Date('2020-01-01'), new Date('2020-01-01'));+ const indexPath = (await execGit(['rev-parse', '--git-path', 'index'], path)).stdout.trim();+ const originalIndex = await readFile(indexPath);const result = await retire(release);- expect(result).toMatchObject({ ok: true, branchDeleted: false });+ expect(result, JSON.stringify(result)).toMatchObject({ ok: true, branchDeleted: false });expect(existsSync(path)).toBe(false);expect(await registered(release.path)).toBe(false);const manifest = JSON.parse(await readFile(join(result.archiveDir, 'manifest.json'), 'utf8'));expect(manifest.release).toEqual(release);+ expect(await readFile(join(result.archiveDir, 'administration', 'gitdir', 'index'))).toEqual(originalIndex);expect(manifest.captured.files.map(file => `${file.path}${file.tracked ? ' (tracked)' : ''}`).sort()).toEqual(['.gitattributes', '.gitignore', 'eol.txt (tracked)', 'ignored.txt', 'initial.txt (tracked)', 'untracked.txt']);expect(await readFile(join(result.archiveDir, 'files', 'eol.txt'), 'utf8')).toBe('one\r\ntwo\r\n');