mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
* fix(devcontainer): move workspace and snapshots to Linux volumes * fix(devcontainer): exclude evaluation virtualenv from source import * fix(devcontainer): preserve WSL links during volume imports * fix(devcontainer): skip parser caches and report import progress Exclude regenerable GitNexus parser caches from every nested worktree while preserving graph databases, Git state, and local work. Report archive bytes and elapsed time every five seconds, and stream output with activity updates during longer Docker initialization stages. * fix(devcontainer): resolve workspace volume ID before startup * fix(devcontainer): relink nested worktrees and harden host imports - Relink nested worktrees whose Git pointers still name the host path (C:/..., /Users/...): match the longest existing suffix in the copy and rewrite both pointers, as `git worktree repair` would. - Fail the import when a file changes while tar reads it. bsdtar on macOS and Windows pads or truncates such files and exits 0. - Disable AppleDouble `._*` entries from macOS tar (COPYFILE_DISABLE). - Follow selected snapshot roots that are symlinks (dotfile-managed ~/.config/gh, ~/.claude.json) like the bind mounts they replace. - Keep node at UID 1000 for root host users; the Dev Containers CLI skips UID realignment for UID 0. - Make fixture modes independent of the process umask and check the no-partial-write case with lstat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(devcontainer): stage on the host and commit once at container creation initializeCommand also runs when an existing container is reopened. A developer who pulled the volume change and reopened the old bind-mount container got an import marked ready, and the eventual rebuild silently showed that stale copy. - The host now only stages the checkout into gitnexus-seed-<id> (tree/ plus a stage-complete marker written last); the helper mounts the source volume read-only. - onCreateCommand, which runs once per container creation, commits a complete stage into the empty source volume, empties the stage and repairs ownership. initializeCommand copies the host's seed-workspace.cjs into the seed volume on every start, so the commit matches devcontainer.json and works with any image. - Staging and snapshot retakes are best-effort: a failure clears its target, warns and is retried next start, so a busy host never locks out reopening an existing container. Creation without a complete stage stops at onCreateCommand with a clear message. - Snapshots are retaken while the source volume is uncommitted, and a partial snapshot is replaced instead of failing closed; snapshots are read-only host copies, so replacing them is safe. - Node writes the tar stream (ustar + PAX for long and UTF-8 names). Windows tar.exe read the file list in the ANSI code page, so any non-ASCII path failed; macOS tar added AppleDouble files; both padded or truncated a file that changed while being read. A changed file now discards that copy. The host no longer needs tar. Sockets and FIFOs are skipped, as tar did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(devcontainer): simplify importer helpers and read small files whole - tarStream reads files up to 1 MiB in one call instead of opening a stream per file: 50k files stream in 1.0 s instead of 12 s, with a byte-identical archive and unchanged change detection. - Drop copyArchive's dead `excludes` parameter; the snapshot marker is excluded through the existing predicate. - Share the source/target overlap check and the common-dir check. - Remove exports with no consumer and two comments left from the host-tar implementation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(devcontainer): skip POSIX-only tar assertions on Windows (#3835) - Address PR review feedback: the tar round-trip test ran mkfifo and asserted a 0755 mode unconditionally. Split it: UTF-8, long-name and empty-file round-trips run everywhere; POSIX mode preservation and FIFO exclusion move to a test skipped on win32, where tarStream writes 0644 by design. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(devcontainer): skip POSIX-tooling importer tests on Windows (#3835) - Address PR review feedback: the Docker-adapter fixture assumed a POSIX PATH separator. A Windows-safe separator would not help: the fake `docker` is a shebang script Windows cannot spawn, and it runs Linux helper commands. One shared `posixOnly` skip option now covers the seven Docker-adapter tests, the bash credential test and the POSIX modes/FIFO test; all still run on Linux. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(devcontainer): keep failed snapshots retryable and nested worktrees local (#3835) Address PR review feedback: - Select snapshot roots with lstat, so a dangling or unfollowable `.claude.json` link reaches the archiver and is preserved as a link. A path under a non-directory still counts as absent. - post-create.sh publishes the one-shot identity and shareable seed markers only when /host carries its completion marker; a snapshot skipped during initialization is seeded by a later rebuild. - Remove an absolute core.worktree from each relinked nested worktree's config.worktree before Git first reads that checkout, as already done for the root configuration. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(devcontainer): run fake-Docker importer tests only on Linux (#3835) - Address PR review feedback: on macOS the importer passes container UID 1000, and the fake Docker adapter ran finishSnapshot's chown as the unprivileged host user. The adapter emulates the Linux helper container on the host, so its seven tests now share a `linuxHelper` gate; the bash, mode and FIFO tests keep the narrower `posixOnly`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci(devcontainer): run host importer tests on macOS and Windows (#3835) Address PR review feedback: the suite's platform assumptions surfaced one review finding per push. The host-side importer now runs on all three CI hosts and the tests state what each one needs. - New `host-importer` job runs initialize-volumes.test.cjs on macos-latest and windows-latest (Linux already runs every test). - The importer reads its Docker CLI from GITNEXUS_IMPORT_DOCKER (JSON argv, default docker). Windows spawn resolves only .exe/.com, so the test adapter is now a Node script on every OS instead of a shebang file on PATH. The adapter emulates the helper's find/mkdir/touch and, on Windows, snapshot finalization. - Gates: posixOnly (bash, modes, mkfifo), a symlink capability probe, and containerSide (Linux only) for code that runs only in the dev container or helper. Host staging assertions read the staged tree; the commit and 0600 snapshot modes stay in one Linux test. - seed-workspace.test.cjs is container-side, so it skips on other hosts. - The long-name round trip stays above 100 bytes (PAX) but under Windows MAX_PATH once extracted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(devcontainer): verify the tar stream with Python's PAX reader (#3835) Windows tar.exe converts names to the ANSI code page while extracting, so it cannot write `jegyzet-ő.md` or an emoji directory ("empty or unreadable filename") - the limitation the Node writer exists to avoid. Production never extracts with it; Docker's Go extractor does. Read the round-trip archive with Python's tarfile instead, an independent PAX reader that handles UTF-8 on every host, so the UTF-8 check also runs on Windows CI. A capability gate skips the test when no Python 3 is installed. Removing the PAX path record fails the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
442 lines
20 KiB
JavaScript
442 lines
20 KiB
JavaScript
'use strict';
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
const { execFileSync, spawnSync } = require('node:child_process');
|
|
const { seedWorkspace, restoreLinks } = require('./seed-workspace.cjs');
|
|
|
|
// seed-workspace.cjs commits the stage and restores links only inside the Linux
|
|
// dev container and import helper; host-side importer tests live in
|
|
// initialize-volumes.test.cjs and run on Linux, macOS and Windows.
|
|
const containerSide = {
|
|
skip: process.platform !== 'linux' && 'runs only inside the Linux dev container and helper',
|
|
};
|
|
|
|
test(
|
|
'symlink restoration rejects traversal, symlink parents and replacements before writing',
|
|
containerSide,
|
|
(t) => {
|
|
const { root, target } = fixture(t);
|
|
const outside = path.join(root, 'outside');
|
|
fs.mkdirSync(outside);
|
|
fs.symlinkSync(outside, path.join(target, 'parent'), 'dir');
|
|
fs.writeFileSync(path.join(target, 'existing'), 'keep');
|
|
for (const links of [
|
|
[['../escape', 'target']],
|
|
[['parent/escape', 'target']],
|
|
[['existing', 'target']],
|
|
[
|
|
['new-link', 'target'],
|
|
['new-link/child', 'target'],
|
|
],
|
|
[
|
|
['new-link/child', 'target'],
|
|
['new-link', 'target'],
|
|
],
|
|
[
|
|
['new-link', 'target'],
|
|
['new-link', 'duplicate'],
|
|
],
|
|
[
|
|
['new-link', 'target'],
|
|
['../escape', 'target'],
|
|
],
|
|
]) {
|
|
assert.throws(() => restoreLinks(target, links));
|
|
// lstat: a created link to the missing 'target' would be dangling.
|
|
assert.equal(
|
|
fs.lstatSync(path.join(target, 'new-link'), { throwIfNoEntry: false }),
|
|
undefined,
|
|
);
|
|
}
|
|
assert.equal(fs.readFileSync(path.join(target, 'existing'), 'utf8'), 'keep');
|
|
assert.deepEqual(fs.readdirSync(outside), []);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'symlink restoration creates missing parents for selected snapshot files',
|
|
containerSide,
|
|
(t) => {
|
|
const { target } = fixture(t);
|
|
restoreLinks(target, [['.config/gh', '../git-config']]);
|
|
assert.equal(fs.readlinkSync(path.join(target, '.config/gh')), '../git-config');
|
|
},
|
|
);
|
|
|
|
function fixture(t, repairOwner = false) {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gn-source-volume-'));
|
|
t.after(() => {
|
|
if (repairOwner)
|
|
execFileSync('sudo', ['chown', '-R', `${process.getuid()}:${process.getgid()}`, root]);
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
});
|
|
const source = path.join(root, 'host');
|
|
const target = path.join(root, 'volume');
|
|
fs.mkdirSync(source);
|
|
fs.mkdirSync(target);
|
|
const git = (cwd, ...args) =>
|
|
execFileSync('git', ['-C', cwd, ...args], { encoding: 'utf8', stdio: 'pipe' }).trim();
|
|
git(source, 'init', '-b', 'local-work');
|
|
git(source, 'config', 'user.name', 'Volume test');
|
|
git(source, 'config', 'user.email', 'volume@example.invalid');
|
|
git(source, 'config', 'commit.gpgsign', 'false');
|
|
git(source, 'config', 'core.hooksPath', '/dev/null');
|
|
fs.writeFileSync(path.join(source, 'tracked'), 'committed\n');
|
|
git(source, 'add', 'tracked');
|
|
git(source, 'commit', '-m', 'local commit');
|
|
return { root, source, target, git };
|
|
}
|
|
|
|
test(
|
|
'seed preserves Git state, local files, indexes, nested worktrees and symlinks',
|
|
containerSide,
|
|
(t) => {
|
|
const { source, target, git } = fixture(t);
|
|
git(source, 'remote', 'add', 'origin', 'https://example.invalid/fork.git');
|
|
fs.writeFileSync(path.join(source, 'tracked'), 'stashed\n');
|
|
git(source, 'stash', 'push');
|
|
fs.writeFileSync(path.join(source, 'tracked'), 'staged\n');
|
|
git(source, 'add', 'tracked');
|
|
fs.writeFileSync(path.join(source, 'tracked'), 'unstaged\n');
|
|
fs.writeFileSync(path.join(source, '.git/commondir'), '.\n');
|
|
fs.writeFileSync(path.join(source, '.git/info/exclude'), 'node_modules/\nignored-local\n');
|
|
fs.writeFileSync(path.join(source, 'ignored-local'), 'local settings\n');
|
|
fs.writeFileSync(path.join(source, 'untracked'), 'untracked\n');
|
|
fs.symlinkSync('tracked', path.join(source, 'relative-link'));
|
|
fs.symlinkSync('missing-file', path.join(source, 'dangling-link'));
|
|
fs.writeFileSync(path.join(source, 'executable'), '#!/bin/sh\n');
|
|
fs.chmodSync(path.join(source, 'executable'), 0o755); // Independent of the process umask.
|
|
for (const file of [
|
|
'.gitnexus/index-sample',
|
|
'.gitnexus/parse-cache/chunk.v8',
|
|
'.gitnexus/parse-cache.json',
|
|
'.gitnexus/parsedfile-cache/chunk.v8',
|
|
'.worktrees/topic/.gitnexus/parse-cache/chunk.v8',
|
|
'.worktrees/topic/.gitnexus/parsedfile-cache/chunk.v8',
|
|
'.worktrees/topic/.gitnexus/lbug',
|
|
'.claude/worktrees/topic/.gitnexus/parse-cache/chunk.v8',
|
|
'.worktrees/topic/local-edit',
|
|
'.git/worktrees/topic/gitdir',
|
|
'eval/.venv/bin/python',
|
|
'eval/.venv/pyvenv.cfg',
|
|
'eval/.venv-notes/local-file',
|
|
'eval/local-script.py',
|
|
'.worktrees/topic/gitnexus-shared/node_modules/binary',
|
|
'.worktrees/topic/eval/.venv/bin/python',
|
|
'.worktrees/topic/.husky/_/h',
|
|
'.claude/worktrees/topic/local-edit',
|
|
'.claude/worktrees/topic/node_modules/binary',
|
|
]) {
|
|
fs.mkdirSync(path.dirname(path.join(source, file)), { recursive: true });
|
|
fs.writeFileSync(path.join(source, file), 'preserve me\n');
|
|
}
|
|
const overlays = [
|
|
'node_modules',
|
|
'gitnexus/node_modules',
|
|
'gitnexus-web/node_modules',
|
|
'gitnexus-shared/node_modules',
|
|
];
|
|
for (const folder of overlays) {
|
|
fs.mkdirSync(path.join(source, folder), { recursive: true });
|
|
fs.mkdirSync(path.join(target, folder), { recursive: true });
|
|
fs.writeFileSync(path.join(source, folder, 'host-dependency'), 'host binary');
|
|
fs.writeFileSync(path.join(target, folder, 'volume-dependency'), 'Linux binary');
|
|
}
|
|
fs.mkdirSync(path.join(source, '.husky/_'), { recursive: true });
|
|
fs.writeFileSync(path.join(source, '.husky/_/h'), 'generated');
|
|
fs.writeFileSync(path.join(source, '.husky/pre-commit'), 'tracked hook');
|
|
const before = git(source, 'status', '--porcelain=v1', '--untracked-files=all');
|
|
const index = fs.readFileSync(path.join(source, '.git/index'));
|
|
assert.equal(seedWorkspace(source, target), true);
|
|
assert.equal(git(target, 'rev-parse', 'HEAD'), git(source, 'rev-parse', 'HEAD'));
|
|
assert.equal(git(target, 'branch', '--show-current'), 'local-work');
|
|
assert.equal(git(target, 'stash', 'list'), git(source, 'stash', 'list'));
|
|
assert.equal(git(target, 'remote', 'get-url', 'origin'), 'https://example.invalid/fork.git');
|
|
assert.equal(git(target, 'show', ':tracked'), 'staged');
|
|
assert.equal(fs.readFileSync(path.join(target, 'tracked'), 'utf8'), 'unstaged\n');
|
|
assert.deepEqual(fs.readFileSync(path.join(target, '.git/index')), index);
|
|
assert.equal(git(source, 'status', '--porcelain=v1', '--untracked-files=all'), before);
|
|
for (const file of [
|
|
'ignored-local',
|
|
'untracked',
|
|
'.gitnexus/index-sample',
|
|
'.worktrees/topic/.gitnexus/lbug',
|
|
'.worktrees/topic/local-edit',
|
|
'.git/worktrees/topic/gitdir',
|
|
'.husky/pre-commit',
|
|
'eval/.venv-notes/local-file',
|
|
'eval/local-script.py',
|
|
]) {
|
|
assert.deepEqual(
|
|
fs.readFileSync(path.join(target, file)),
|
|
fs.readFileSync(path.join(source, file)),
|
|
);
|
|
}
|
|
assert.equal(fs.readlinkSync(path.join(target, 'relative-link')), 'tracked');
|
|
assert.equal(fs.readlinkSync(path.join(target, 'dangling-link')), 'missing-file');
|
|
assert.equal(fs.statSync(path.join(target, 'executable')).mode & 0o777, 0o755);
|
|
assert.equal(fs.existsSync(path.join(target, '.husky/_')), false);
|
|
assert.equal(fs.existsSync(path.join(target, 'eval/.venv')), false);
|
|
for (const folder of [
|
|
'.gitnexus/parse-cache',
|
|
'.gitnexus/parse-cache.json',
|
|
'.gitnexus/parsedfile-cache',
|
|
'.worktrees/topic/.gitnexus/parse-cache',
|
|
'.worktrees/topic/.gitnexus/parsedfile-cache',
|
|
'.claude/worktrees/topic/.gitnexus/parse-cache',
|
|
'.worktrees/topic/gitnexus-shared/node_modules',
|
|
'.worktrees/topic/eval/.venv',
|
|
'.worktrees/topic/.husky/_',
|
|
'.claude/worktrees/topic/node_modules',
|
|
]) {
|
|
assert.equal(fs.existsSync(path.join(target, folder)), false, folder);
|
|
assert.equal(fs.existsSync(path.join(source, folder)), true, `host keeps ${folder}`);
|
|
}
|
|
assert.equal(
|
|
fs.readFileSync(path.join(target, '.claude/worktrees/topic/local-edit'), 'utf8'),
|
|
'preserve me\n',
|
|
);
|
|
for (const folder of overlays) {
|
|
assert.equal(fs.existsSync(path.join(target, folder, 'host-dependency')), false);
|
|
assert.equal(
|
|
fs.readFileSync(path.join(target, folder, 'volume-dependency'), 'utf8'),
|
|
'Linux binary',
|
|
);
|
|
}
|
|
},
|
|
);
|
|
|
|
test(
|
|
'recreation keeps volume edits and never synchronizes later host changes',
|
|
containerSide,
|
|
(t) => {
|
|
const { source, target } = fixture(t);
|
|
seedWorkspace(source, target);
|
|
fs.writeFileSync(path.join(target, 'tracked'), 'volume work');
|
|
fs.writeFileSync(path.join(target, 'new-volume-file'), 'new work');
|
|
fs.writeFileSync(path.join(source, 'tracked'), 'changed host');
|
|
fs.writeFileSync(path.join(source, 'host-only'), 'do not copy');
|
|
assert.equal(seedWorkspace(source, target), false);
|
|
assert.equal(fs.readFileSync(path.join(target, 'tracked'), 'utf8'), 'volume work');
|
|
assert.equal(fs.readFileSync(path.join(target, 'new-volume-file'), 'utf8'), 'new work');
|
|
assert.equal(fs.existsSync(path.join(target, 'host-only')), false);
|
|
// A previously seeded host checkout must not publish its old marker early.
|
|
const next = path.join(path.dirname(target), 'next-volume');
|
|
fs.mkdirSync(next);
|
|
assert.equal(seedWorkspace(target, next), true);
|
|
assert.equal(fs.readFileSync(path.join(next, 'tracked'), 'utf8'), 'volume work');
|
|
},
|
|
);
|
|
|
|
test('seed clears core.worktree only in the copy', containerSide, (t) => {
|
|
const { source, target, git } = fixture(t);
|
|
git(source, 'config', 'core.worktree', source);
|
|
git(source, 'config', 'extensions.worktreeConfig', 'true');
|
|
git(source, 'config', '--worktree', 'core.worktree', source);
|
|
seedWorkspace(source, target);
|
|
assert.equal(git(source, 'config', '--get', 'core.worktree'), source);
|
|
assert.equal(git(source, 'config', '--worktree', '--get', 'core.worktree'), source);
|
|
assert.equal(git(target, 'rev-parse', '--show-toplevel'), target);
|
|
});
|
|
|
|
test('seed refuses a symlinked Git config without modifying its target', containerSide, (t) => {
|
|
const { root, source, target } = fixture(t);
|
|
const external = path.join(root, 'external-config');
|
|
fs.renameSync(path.join(source, '.git/config'), external);
|
|
const original = fs.readFileSync(external);
|
|
fs.symlinkSync(external, path.join(source, '.git/config'));
|
|
assert.throws(() => seedWorkspace(source, target), /regular file/);
|
|
assert.deepEqual(fs.readFileSync(external), original);
|
|
assert.deepEqual(fs.readdirSync(target), []);
|
|
});
|
|
|
|
test(
|
|
'refuses incomplete copies and unexpected files even inside mount parents',
|
|
containerSide,
|
|
(t) => {
|
|
const { source, target } = fixture(t);
|
|
for (const entry of ['.git/HEAD', 'gitnexus/local-work', 'untracked']) {
|
|
fs.mkdirSync(path.dirname(path.join(target, entry)), { recursive: true });
|
|
fs.writeFileSync(path.join(target, entry), 'keep');
|
|
assert.throws(() => seedWorkspace(source, target), /Uninitialized source volume/);
|
|
assert.equal(fs.readFileSync(path.join(target, entry), 'utf8'), 'keep');
|
|
assert.equal(fs.existsSync(path.join(target, '.git/devcontainer-source-volume')), false);
|
|
fs.rmSync(path.join(target, entry.split('/')[0]), { recursive: true });
|
|
}
|
|
fs.symlinkSync(source, path.join(target, 'gitnexus'));
|
|
assert.throws(() => seedWorkspace(source, target), /Uninitialized source volume/);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'refuses linked checkouts, external object stores, active Git operations and nested targets',
|
|
containerSide,
|
|
(t) => {
|
|
const { root, source, target, git } = fixture(t);
|
|
const linked = path.join(root, 'linked');
|
|
git(source, 'worktree', 'add', '--detach', linked);
|
|
assert.throws(() => seedWorkspace(linked, target), /full Git checkout/);
|
|
fs.writeFileSync(path.join(source, '.git/objects/info/alternates'), '/some/other/objects\n');
|
|
assert.throws(() => seedWorkspace(source, target), /own Git object database/);
|
|
fs.rmSync(path.join(source, '.git/objects/info/alternates'));
|
|
fs.writeFileSync(path.join(source, '.git/commondir'), path.join(source, '.git/objects'));
|
|
assert.throws(() => seedWorkspace(source, target), /own Git object database/);
|
|
fs.rmSync(path.join(source, '.git/commondir'));
|
|
fs.writeFileSync(path.join(source, '.git/index.lock'), 'busy');
|
|
assert.throws(() => seedWorkspace(source, target), /Git operation is active/);
|
|
fs.rmSync(path.join(source, '.git/index.lock'));
|
|
assert.throws(() => seedWorkspace(source, source), /separate directories/);
|
|
const nested = path.join(source, 'nested');
|
|
fs.mkdirSync(nested);
|
|
assert.throws(() => seedWorkspace(source, nested), /separate directories/);
|
|
assert.deepEqual(fs.readdirSync(target), []);
|
|
},
|
|
);
|
|
test(
|
|
'root preparation recovers an inaccessible old-UID volume and prunes dependencies',
|
|
containerSide,
|
|
(t) => {
|
|
if (spawnSync('sudo', ['-n', 'true']).status !== 0) return t.skip('requires passwordless sudo');
|
|
const { root, source, target } = fixture(t, true);
|
|
seedWorkspace(source, target);
|
|
const staging = path.join(root, 'seed');
|
|
fs.mkdirSync(path.join(staging, 'tree/leftover'), { recursive: true });
|
|
fs.writeFileSync(path.join(staging, 'stage-complete'), '');
|
|
const dependency = path.join(target, 'gitnexus/node_modules');
|
|
fs.mkdirSync(dependency, { recursive: true });
|
|
fs.chmodSync(dependency, 0o755); // Let the test stat it after the foreign chown.
|
|
fs.writeFileSync(path.join(dependency, 'keep-owner'), 'binary');
|
|
execFileSync('sudo', ['chown', '-R', '20001:20001', target]);
|
|
execFileSync('sudo', ['chmod', '700', path.join(target, '.git')]);
|
|
const result = spawnSync(
|
|
'sudo',
|
|
[
|
|
'-n',
|
|
process.execPath,
|
|
path.join(__dirname, 'seed-workspace.cjs'),
|
|
'--prepare',
|
|
target,
|
|
staging,
|
|
],
|
|
{ encoding: 'utf8' },
|
|
);
|
|
assert.equal(result.status, 0, result.stderr);
|
|
assert.equal(fs.statSync(path.join(target, '.git')).uid, process.getuid());
|
|
assert.equal(fs.statSync(path.join(dependency, 'keep-owner')).uid, 20001);
|
|
assert.deepEqual(fs.readdirSync(staging), []); // A ready volume discards the stale stage.
|
|
assert.equal(seedWorkspace('/missing-host', target), false);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'rejects an absolute self commondir before copying or modifying either repository',
|
|
containerSide,
|
|
(t) => {
|
|
const { source, target } = fixture(t);
|
|
fs.writeFileSync(path.join(source, '.git/commondir'), path.join(source, '.git'));
|
|
const config = fs.readFileSync(path.join(source, '.git/config'));
|
|
assert.throws(() => seedWorkspace(source, target), /commondir must be/);
|
|
assert.deepEqual(fs.readdirSync(target), []);
|
|
assert.deepEqual(fs.readFileSync(path.join(source, '.git/config')), config);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'adapts Windows flags, executable modes and symlinks while preserving local edits and index',
|
|
containerSide,
|
|
(t) => {
|
|
const { source, target, git } = fixture(t);
|
|
fs.writeFileSync(path.join(source, 'foo.ts'), 'original');
|
|
fs.writeFileSync(path.join(source, 'script'), '#!/bin/sh\n', { mode: 0o755 });
|
|
fs.symlinkSync('foo.ts', path.join(source, 'link'));
|
|
fs.symlinkSync('foo.ts', path.join(source, 'edited-link'));
|
|
git(source, 'add', '.');
|
|
git(source, 'commit', '-m', 'Linux modes before Windows checkout');
|
|
for (const name of ['link', 'edited-link']) {
|
|
fs.unlinkSync(path.join(source, name));
|
|
fs.writeFileSync(path.join(source, name), name === 'link' ? 'foo.ts' : 'local link edits');
|
|
}
|
|
fs.chmodSync(path.join(source, 'script'), 0o644);
|
|
fs.chmodSync(path.join(source, 'foo.ts'), 0o755);
|
|
git(source, 'config', 'extensions.worktreeConfig', 'true');
|
|
for (const [key, value] of [
|
|
['core.filemode', 'false'],
|
|
['core.ignorecase', 'true'],
|
|
['core.symlinks', 'false'],
|
|
]) {
|
|
git(source, 'config', key, value);
|
|
git(source, 'config', '--worktree', key, value);
|
|
}
|
|
fs.writeFileSync(path.join(source, 'tracked'), 'staged');
|
|
git(source, 'add', 'tracked');
|
|
fs.writeFileSync(path.join(source, 'tracked'), 'unstaged');
|
|
const index = fs.readFileSync(path.join(source, '.git/index'));
|
|
seedWorkspace(source, target);
|
|
assert.deepEqual(fs.readFileSync(path.join(target, '.git/index')), index);
|
|
assert.equal(git(target, 'show', ':tracked'), 'staged');
|
|
assert.equal(fs.readFileSync(path.join(target, 'tracked'), 'utf8'), 'unstaged');
|
|
assert.equal(git(target, 'config', 'core.ignorecase'), 'false');
|
|
assert.equal(git(target, 'config', 'core.filemode'), 'true');
|
|
assert.equal(git(target, 'config', 'core.symlinks'), 'true');
|
|
assert.equal(fs.statSync(path.join(target, 'script')).mode & 0o111, 0o111);
|
|
assert.equal(fs.statSync(path.join(target, 'foo.ts')).mode & 0o111, 0);
|
|
assert.equal(fs.readlinkSync(path.join(target, 'link')), 'foo.ts');
|
|
assert.equal(fs.readFileSync(path.join(target, 'edited-link'), 'utf8'), 'local link edits');
|
|
fs.writeFileSync(path.join(target, 'Foo.ts'), 'case-sensitive new file');
|
|
fs.chmodSync(path.join(target, 'script'), 0o644);
|
|
const status = git(target, 'status', '--porcelain');
|
|
assert.match(status, /\?\? Foo.ts/);
|
|
assert.match(status, / M script/);
|
|
assert.equal(git(source, 'config', 'core.ignorecase'), 'true');
|
|
assert.equal(fs.lstatSync(path.join(source, 'link')).isFile(), true);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'normalizes a nested worktree with independent Windows filesystem overrides',
|
|
containerSide,
|
|
(t) => {
|
|
const { source, target, git } = fixture(t);
|
|
fs.writeFileSync(path.join(source, 'script'), '#!/bin/sh\n', { mode: 0o755 });
|
|
git(source, 'add', 'script');
|
|
git(source, 'commit', '-m', 'executable');
|
|
git(source, 'config', 'extensions.worktreeConfig', 'true');
|
|
const nested = path.join(source, '.worktrees/topic');
|
|
git(source, 'worktree', 'add', '--detach', nested);
|
|
for (const [key, value] of [
|
|
['core.filemode', 'false'],
|
|
['core.ignorecase', 'true'],
|
|
])
|
|
git(nested, 'config', '--worktree', key, value);
|
|
fs.chmodSync(path.join(nested, 'script'), 0o644);
|
|
fs.writeFileSync(path.join(nested, 'tracked'), 'nested local edits');
|
|
const index = fs.readFileSync(path.join(source, '.git/worktrees/topic/index'));
|
|
// A host-created worktree records host paths that do not exist in the volume.
|
|
const host = 'C:/Users/dev/GitNexus';
|
|
git(nested, 'config', '--worktree', 'core.worktree', `${host}/.worktrees/topic`);
|
|
const nestedConfig = path.join(source, '.git/worktrees/topic/config.worktree');
|
|
const registration = path.join(source, '.git/worktrees/topic/gitdir');
|
|
fs.writeFileSync(registration, `${host}/.worktrees/topic/.git\n`);
|
|
fs.writeFileSync(path.join(nested, '.git'), `gitdir: ${host}/.git/worktrees/topic\n`);
|
|
seedWorkspace(source, target);
|
|
const copied = path.join(target, '.worktrees/topic');
|
|
assert.equal(git(copied, 'rev-parse', '--show-toplevel'), copied);
|
|
assert.throws(() => git(copied, 'config', '--worktree', '--get-all', 'core.worktree'), {
|
|
status: 1,
|
|
});
|
|
assert.equal(
|
|
git(source, 'config', '--file', nestedConfig, 'core.worktree'),
|
|
`${host}/.worktrees/topic`,
|
|
);
|
|
assert.equal(git(target, 'worktree', 'list', '--porcelain').includes(copied), true);
|
|
assert.equal(fs.readFileSync(registration, 'utf8'), `${host}/.worktrees/topic/.git\n`);
|
|
assert.equal(git(copied, 'config', 'core.filemode'), 'true');
|
|
assert.equal(git(copied, 'config', 'core.ignorecase'), 'false');
|
|
assert.equal(fs.statSync(path.join(copied, 'script')).mode & 0o111, 0o111);
|
|
assert.equal(fs.readFileSync(path.join(copied, 'tracked'), 'utf8'), 'nested local edits');
|
|
assert.deepEqual(fs.readFileSync(path.join(target, '.git/worktrees/topic/index')), index);
|
|
},
|
|
);
|