mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
Some checks are pending
Devcontainer Smoke / Config-transform unit tests (push) Waiting to run
Devcontainer Smoke / Host importer tests (macos-latest) (push) Waiting to run
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
Publish Development Images / publish (core) (push) Waiting to run
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Devcontainer Smoke / Host importer tests (windows-latest) (push) Waiting to run
Devcontainer Smoke / Build devcontainer image (default) (push) Waiting to run
Devcontainer Smoke / Build devcontainer image (ui) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Publish Development Images / publish (ui) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Skill copy sync / shipped skills drift guard (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
* fix(hooks): show the stale-index hint after git commands with global options `git -c user.name=x commit`, `git -C ../other commit` and `git --no-pager pull` did not trigger the stale-index hint in the Claude and Antigravity adapters: their regex wanted the subcommand right after `git`. Both adapters now ask one helper, git-mutation-command.cjs, which skips git's global options and their values before reading the subcommand. Everything the previous regex matched still matches. Closes #3897 * fix(hooks): check the index of the repository `git -C` names After `git -C ../other commit` the adapters compared the HEAD and the index of the repository the hook runs in, not the one the command changed. The helper now returns the directory git ran in, and the adapters use it for the repository lookup and for `git rev-parse HEAD`. The hint names the repository when the agent is not working in it. When the shell computes the path, or `--git-dir` / `--work-tree` point git elsewhere, no check is made. * fix(hooks): follow symlinks in a `git -C` path the way git does `git -C link/..` goes to the parent of the link's target: git changes directory through the filesystem. Resolving the path by its text gave the parent of the link, so the adapters could check another repository. * test(hooks): run the bare-backslash case as one test on every platform The two tests each ran on one platform only, so one of them was unverified wherever the file ran. One test now picks its command and expected directory from the platform, and the file joins the cross-platform subset so that the Windows half is read on windows-latest. * fix(hooks): read every git call of a command, in the shell that ran it Review follow-up on the stale-index hint after `git -C`. - The helper takes the shell from the adapter: bash, powershell, or either when the runtime cannot tell which of the two read the command. Its word rule is built from that shell, and a word it cannot decode is left out. The decoder ends on every input. - Every git call of a command is placed, not only the first, so one that cannot be placed no longer hides a plain `git commit` after it. A relative `-C` that follows a `cd` is left out. Antigravity reads `dir_path`. - The checkout named in the hint comes from git (`rev-parse --show-toplevel`): a linked worktree or a nested clone is named for itself, and a plain commit keeps the text it had. - Git always starts in the session directory and reaches the target through `-C`. Network paths are refused on Windows, and the exit code is read before the command. - A command above 16 KB is matched without options. Attached `-C<path>` and `-c<name>` no longer match, `--no-literal-pathspecs` does, and a subcommand may end at `;`, `&`, `|` or `)`. - Only a commit id from the index metadata is echoed. - Setup copies the helpers before it writes the adapter. * fix(hooks): avoid stale hints after shell directory changes Skip an option-bearing Git mutation when a preceding directory change leaves its checkout unknown. Keep the existing behavior for plain commands and absolute -C targets. --------- Co-authored-by: Gergő Magyar <gergomagyar@icloud.com> Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
462 lines
17 KiB
JavaScript
462 lines
17 KiB
JavaScript
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const { createHash } = require('crypto');
|
|
const { spawnSync } = require('child_process');
|
|
|
|
// Hooks are copied into editor-specific directories and run without the
|
|
// package's TypeScript modules. Keep their on-disk names centralized here.
|
|
const GITNEXUS_DIR = '.gitnexus';
|
|
const INDEX_METADATA_FILE = 'gitnexus.json';
|
|
const LEGACY_METADATA_FILE = 'meta.json';
|
|
const LBUG_DIRECTORY = 'lbug';
|
|
const BRANCHES_DIRECTORY = 'branches';
|
|
const STORAGE_PATH_ENV = 'GITNEXUS_STORAGE_PATH';
|
|
const STORAGE_ROOT_ENV = 'GITNEXUS_STORAGE_ROOT';
|
|
const STORAGE_SLOT_HASH_LENGTH = 12;
|
|
const LOCAL_OWNED_PARENT_HOPS = 5;
|
|
|
|
function stripWindowsLongPathPrefix(p) {
|
|
if (process.platform !== 'win32') return p;
|
|
if (/^\\\\\?\\UNC\\(?=[^\\])/i.test(p)) return `\\\\${p.slice(8)}`;
|
|
if (/^\\\\\?\\[A-Za-z]:\\/.test(p)) return p.slice(4);
|
|
return p;
|
|
}
|
|
|
|
function canonicalize(value) {
|
|
if (typeof value !== 'string' || !value || value.includes('\0') || !path.isAbsolute(value))
|
|
return null;
|
|
const resolved = path.resolve(value);
|
|
try {
|
|
return stripWindowsLongPathPrefix(fs.realpathSync.native(resolved));
|
|
} catch {
|
|
return stripWindowsLongPathPrefix(resolved);
|
|
}
|
|
}
|
|
|
|
function samePath(left, right) {
|
|
if (left == null || right == null) return false;
|
|
return process.platform === 'win32' ? left.toLowerCase() === right.toLowerCase() : left === right;
|
|
}
|
|
|
|
function isMissingFile(error) {
|
|
return error && (error.code === 'ENOENT' || error.code === 'ENOTDIR');
|
|
}
|
|
|
|
function readMetadataFile(storagePath, filename) {
|
|
try {
|
|
const value = JSON.parse(fs.readFileSync(path.join(storagePath, filename), 'utf-8'));
|
|
return value && typeof value === 'object' && !Array.isArray(value)
|
|
? { state: 'valid', value }
|
|
: { state: 'invalid' };
|
|
} catch (error) {
|
|
return isMissingFile(error) ? { state: 'absent' } : { state: 'invalid' };
|
|
}
|
|
}
|
|
|
|
function readIndexMetadata(storagePath) {
|
|
const primary = readMetadataFile(storagePath, INDEX_METADATA_FILE);
|
|
if (primary.state === 'valid') return primary.value;
|
|
if (primary.state !== 'absent') return null;
|
|
|
|
const legacy = readMetadataFile(storagePath, LEGACY_METADATA_FILE);
|
|
return legacy.state === 'valid' ? legacy.value : null;
|
|
}
|
|
|
|
function isOwnedStorage(repoPath, storagePath, repositoryLocal, metadata) {
|
|
// Repository-local storage remains usable for metadata written before
|
|
// repoPath was recorded, but an explicit repoPath must never name another
|
|
// checkout. External storage always requires the complete ownership binding.
|
|
if (repositoryLocal && (!metadata || typeof metadata.repoPath !== 'string')) {
|
|
return true;
|
|
}
|
|
if (!metadata || typeof metadata.repoPath !== 'string') return false;
|
|
|
|
const metadataRepoPath = canonicalize(metadata.repoPath);
|
|
const expectedRepoPath = canonicalize(repoPath);
|
|
if (
|
|
metadataRepoPath == null ||
|
|
expectedRepoPath == null ||
|
|
!samePath(metadataRepoPath, expectedRepoPath)
|
|
) {
|
|
return false;
|
|
}
|
|
if (repositoryLocal) return true;
|
|
if (typeof metadata.storagePath !== 'string') return false;
|
|
|
|
const metadataStoragePath = canonicalize(metadata.storagePath);
|
|
const expectedStoragePath = canonicalize(storagePath);
|
|
return (
|
|
metadataStoragePath != null &&
|
|
expectedStoragePath != null &&
|
|
samePath(metadataStoragePath, expectedStoragePath)
|
|
);
|
|
}
|
|
|
|
function ancestorPaths(cwd) {
|
|
const paths = [];
|
|
let current = canonicalize(cwd);
|
|
while (current) {
|
|
paths.push(current);
|
|
const parent = path.dirname(current);
|
|
if (parent === current) break;
|
|
current = parent;
|
|
}
|
|
return paths;
|
|
}
|
|
|
|
function isInsideOrEqual(child, ancestor) {
|
|
if (child == null || ancestor == null) return false;
|
|
if (samePath(child, ancestor)) return true;
|
|
const relative = path.relative(ancestor, child);
|
|
return (
|
|
relative !== '' &&
|
|
relative !== '..' &&
|
|
!relative.startsWith(`..${path.sep}`) &&
|
|
!path.isAbsolute(relative)
|
|
);
|
|
}
|
|
|
|
function ancestorPathsThrough(cwd, stopAt) {
|
|
const paths = [];
|
|
let current = canonicalize(cwd);
|
|
const stop = canonicalize(stopAt);
|
|
while (current) {
|
|
if (stop && !isInsideOrEqual(current, stop)) break;
|
|
paths.push(current);
|
|
if (stop && samePath(current, stop)) break;
|
|
const parent = path.dirname(current);
|
|
if (parent === current) break;
|
|
current = parent;
|
|
}
|
|
return paths;
|
|
}
|
|
|
|
// Git starts in `spawnCwd` and reads `cwd` through -C when the two differ. A
|
|
// caller that only read `cwd` in a command must not start git there: Windows
|
|
// looks for `git.exe` in the working directory of the child before PATH.
|
|
function gitFor(cwd, spawnCwd, args) {
|
|
return spawnSync('git', cwd === spawnCwd ? args : ['-C', cwd, ...args], {
|
|
encoding: 'utf-8',
|
|
timeout: 2000,
|
|
cwd: spawnCwd,
|
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
windowsHide: true,
|
|
});
|
|
}
|
|
|
|
function currentGitBranch(cwd, spawnCwd) {
|
|
try {
|
|
const result = gitFor(cwd, spawnCwd, ['symbolic-ref', '--quiet', '--short', 'HEAD']);
|
|
if (result.error || result.status !== 0) return null;
|
|
const branch = String(result.stdout || '').trim();
|
|
return branch || null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function registryPathsForCwd(cwd, spawnCwd) {
|
|
const fallbackPaths = ancestorPaths(cwd);
|
|
if (fallbackPaths.length === 0) return { repoPaths: [], branch: null };
|
|
try {
|
|
const result = gitFor(cwd, spawnCwd, [
|
|
'rev-parse',
|
|
'--path-format=absolute',
|
|
'--show-toplevel',
|
|
'--git-common-dir',
|
|
]);
|
|
if (result.error || result.status !== 0) return { repoPaths: fallbackPaths, branch: null };
|
|
|
|
const [worktreeRoot, commonDir] = String(result.stdout || '')
|
|
.split(/\r?\n/)
|
|
.map((line) => line.trim())
|
|
.filter(Boolean);
|
|
if (!worktreeRoot || !path.isAbsolute(worktreeRoot)) {
|
|
return { repoPaths: fallbackPaths, branch: null };
|
|
}
|
|
|
|
// Keep ancestor paths of cwd that stay inside this worktree (cwd up to
|
|
// and including show-toplevel) so a --skip-git subdirectory index can
|
|
// win via longest-match. Do not walk ancestors outside the worktree —
|
|
// that would re-attribute a parent index to a nested git checkout.
|
|
const repoPaths = ancestorPathsThrough(cwd, worktreeRoot);
|
|
const worktreeCanon = canonicalize(worktreeRoot);
|
|
if (worktreeCanon && !repoPaths.some((repoPath) => samePath(repoPath, worktreeCanon))) {
|
|
repoPaths.push(worktreeCanon);
|
|
}
|
|
|
|
// Linked worktrees share the canonical repo's git dir. Include that
|
|
// parent so the registered main checkout is still discoverable, but do
|
|
// not walk any further outside this worktree.
|
|
if (commonDir) {
|
|
const commonParent = canonicalize(path.dirname(commonDir));
|
|
if (
|
|
commonParent &&
|
|
worktreeCanon &&
|
|
!samePath(commonParent, worktreeCanon) &&
|
|
!repoPaths.some((repoPath) => samePath(repoPath, commonParent))
|
|
) {
|
|
repoPaths.push(commonParent);
|
|
}
|
|
}
|
|
return {
|
|
repoPaths,
|
|
branch: currentGitBranch(cwd, spawnCwd),
|
|
};
|
|
} catch {
|
|
return { repoPaths: fallbackPaths, branch: null };
|
|
}
|
|
}
|
|
|
|
function branchSlug(rawRef) {
|
|
const sanitized = rawRef.replace(/^-+/, '').replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
const reserved = /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\..*)?$/i;
|
|
const safe =
|
|
!sanitized || sanitized === '.' || sanitized === '..' || reserved.test(sanitized)
|
|
? 'unknown'
|
|
: sanitized;
|
|
const hash = createHash('sha256').update(rawRef).digest('hex').slice(0, 8);
|
|
return `${safe}-${hash}`;
|
|
}
|
|
|
|
// Mirror gitnexus/src/storage/storage-slot.ts slotNameForCanonicalPath exactly
|
|
// (sanitize + sha256 of the canonical repo path, 12-hex suffix).
|
|
function sanitizeSlotBasename(value) {
|
|
// Cap first, then walk the tail once — same order as
|
|
// gitnexus/src/storage/storage-slot.ts (avoids /[. ]+$/ ReDoS).
|
|
const sanitized = value.replace(/[\u0000-\u001f<>:"/\\|?*]/g, '-').slice(0, 80);
|
|
let end = sanitized.length;
|
|
while (end > 0) {
|
|
const code = sanitized.charCodeAt(end - 1);
|
|
if (code !== 0x20 && code !== 0x2e) break;
|
|
end--;
|
|
}
|
|
const candidate = sanitized.slice(0, end) || 'repository';
|
|
// Windows also reserves device names with an extension (`CON.txt`); same
|
|
// platform branch as gitnexus/src/storage/storage-slot.ts.
|
|
const reserved =
|
|
process.platform === 'win32'
|
|
? /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i
|
|
: /^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;
|
|
return reserved.test(candidate) ? `repository-${candidate}` : candidate;
|
|
}
|
|
|
|
function storageSlotName(repoPath) {
|
|
const canonical = canonicalize(repoPath);
|
|
if (!canonical) return null;
|
|
const identity = process.platform === 'win32' ? canonical.toLowerCase() : canonical;
|
|
const basename = sanitizeSlotBasename(path.basename(canonical));
|
|
const digest = createHash('sha256')
|
|
.update(identity)
|
|
.digest('hex')
|
|
.slice(0, STORAGE_SLOT_HASH_LENGTH);
|
|
return `${basename}-${digest}`;
|
|
}
|
|
|
|
// Definedness matches the CLI's storage-resolver.ts: any value other than
|
|
// undefined (including '') counts as configured.
|
|
function envOverridesStorage() {
|
|
return process.env[STORAGE_PATH_ENV] !== undefined || process.env[STORAGE_ROOT_ENV] !== undefined;
|
|
}
|
|
|
|
// A set-but-invalid override (empty, relative, or containing NUL) makes
|
|
// storage unresolvable (the CLI's storage-resolver.ts throws); never fall
|
|
// back to the registry row. A filesystem root is invalid only for
|
|
// GITNEXUS_STORAGE_PATH (validateConfiguredStoragePath rejects it);
|
|
// GITNEXUS_STORAGE_ROOT accepts a filesystem root — storagePathFromRoot
|
|
// resolves the slot directly under it.
|
|
function resolveEntryStoragePath(entry) {
|
|
const envPath = process.env[STORAGE_PATH_ENV];
|
|
if (envPath !== undefined) {
|
|
if (!envPath || envPath.includes('\0') || !path.isAbsolute(envPath)) return null;
|
|
const resolved = path.resolve(envPath);
|
|
// validateConfiguredStoragePath rejects a filesystem root.
|
|
return path.basename(resolved) ? resolved : null;
|
|
}
|
|
|
|
const envRoot = process.env[STORAGE_ROOT_ENV];
|
|
if (envRoot !== undefined) {
|
|
if (!envRoot || envRoot.includes('\0') || !path.isAbsolute(envRoot)) return null;
|
|
const root = path.resolve(envRoot);
|
|
const slot = storageSlotName(entry.path);
|
|
if (!slot) return null;
|
|
const storagePath = path.join(root, slot);
|
|
return samePath(path.dirname(storagePath), root) ? storagePath : null;
|
|
}
|
|
|
|
if (entry.storagePath !== undefined) {
|
|
if (
|
|
typeof entry.storagePath !== 'string' ||
|
|
!entry.storagePath ||
|
|
entry.storagePath.includes('\0') ||
|
|
!path.isAbsolute(entry.storagePath)
|
|
) {
|
|
return null;
|
|
}
|
|
return path.resolve(entry.storagePath);
|
|
}
|
|
return path.resolve(path.join(entry.path, GITNEXUS_DIR));
|
|
}
|
|
|
|
// A single path segment: `..repo-<hash>` is a legal slot name, `..` is not.
|
|
function isDirectChild(parent, child) {
|
|
const rel = path.relative(parent, child);
|
|
return rel !== '' && rel !== '..' && !path.isAbsolute(rel) && !rel.includes(path.sep);
|
|
}
|
|
|
|
// Mirror gitnexus/src/storage/shared-store.ts resolveGraphPath (#3352): a
|
|
// slot may read an owned private generation; shared checkout slots may also
|
|
// read a commit graph in the same store. Other recorded values are ignored.
|
|
function resolveGraphPath(storagePath, metadata) {
|
|
const own = path.join(storagePath, LBUG_DIRECTORY);
|
|
const recorded = metadata && metadata.graphPath;
|
|
if (typeof recorded === 'string' && /^lbug\.generation\.[a-f0-9]{32}$/.test(recorded)) {
|
|
const graph = path.join(storagePath, recorded);
|
|
try {
|
|
const stat = fs.lstatSync(graph);
|
|
if (!stat.isFile() || stat.isSymbolicLink()) return null;
|
|
} catch (error) {
|
|
if (!error || error.code !== 'ENOENT') return null;
|
|
}
|
|
return graph;
|
|
}
|
|
const storesRoot = path.resolve(
|
|
process.env.GITNEXUS_HOME || path.join(os.homedir(), '.gitnexus'),
|
|
'stores',
|
|
);
|
|
const slot = path.resolve(storagePath);
|
|
const checkoutsDir = path.dirname(slot);
|
|
const root = path.dirname(checkoutsDir);
|
|
if (path.basename(checkoutsDir) !== 'checkouts') return own;
|
|
if (!isDirectChild(checkoutsDir, slot) || !isDirectChild(storesRoot, root)) return own;
|
|
if (typeof recorded !== 'string' || !path.isAbsolute(recorded)) return own;
|
|
const graph = path.resolve(recorded);
|
|
// Only a published `<commit>-<featureKey>` dir, never `.publish-*` staging.
|
|
const valid =
|
|
path.basename(graph) === LBUG_DIRECTORY &&
|
|
isDirectChild(path.join(root, 'commits'), path.dirname(graph)) &&
|
|
/^[0-9a-f]{7,64}-[0-9a-f]{8,64}$/.test(path.basename(path.dirname(graph)));
|
|
return valid ? graph : own;
|
|
}
|
|
|
|
function hasLocalIndexSignal(storagePath) {
|
|
try {
|
|
return (
|
|
fs.existsSync(path.join(storagePath, INDEX_METADATA_FILE)) ||
|
|
fs.existsSync(path.join(storagePath, LBUG_DIRECTORY))
|
|
);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function findLocalOwnedRepo(cwd, spawnCwd = cwd) {
|
|
// Environment storage overrides win; a leftover repo-local .gitnexus must
|
|
// not skip the registry scan that applies STORAGE_PATH / STORAGE_ROOT.
|
|
if (envOverridesStorage()) return null;
|
|
const { repoPaths, branch } = registryPathsForCwd(cwd, spawnCwd);
|
|
let current = canonicalize(cwd);
|
|
for (let hops = 0; hops <= LOCAL_OWNED_PARENT_HOPS && current; hops++) {
|
|
const storagePath = path.join(current, GITNEXUS_DIR);
|
|
if (hasLocalIndexSignal(storagePath)) {
|
|
const metadata = readIndexMetadata(storagePath);
|
|
if (isOwnedStorage(current, storagePath, true, metadata)) {
|
|
const branchDir =
|
|
branch != null ? path.join(storagePath, BRANCHES_DIRECTORY, branchSlug(branch)) : null;
|
|
const indexDir = branchDir && hasLocalIndexSignal(branchDir) ? branchDir : storagePath;
|
|
const indexMetadata = indexDir === storagePath ? metadata : readIndexMetadata(indexDir);
|
|
const lbugPath = resolveGraphPath(indexDir, indexMetadata);
|
|
if (!lbugPath) return null;
|
|
return {
|
|
path: current,
|
|
storagePath,
|
|
lbugPath,
|
|
metadata: indexMetadata,
|
|
};
|
|
}
|
|
}
|
|
const parent = path.dirname(current);
|
|
if (parent === current) break;
|
|
// Stay inside this checkout. Registered lookup already stops at
|
|
// `--show-toplevel`; walking raw parents would adopt `/outer/.gitnexus`
|
|
// from `/outer/nested-repo`.
|
|
if (repoPaths.length > 0 && !repoPaths.some((repoPath) => samePath(repoPath, parent))) {
|
|
break;
|
|
}
|
|
current = parent;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function findRegisteredRepo(cwd, spawnCwd = cwd) {
|
|
const { repoPaths, branch } = registryPathsForCwd(cwd, spawnCwd);
|
|
if (repoPaths.length === 0) return null;
|
|
|
|
const home = process.env.GITNEXUS_HOME || path.join(os.homedir(), '.gitnexus');
|
|
let entries;
|
|
try {
|
|
entries = JSON.parse(fs.readFileSync(path.join(home, 'registry.json'), 'utf-8'));
|
|
} catch {
|
|
return null;
|
|
}
|
|
if (!Array.isArray(entries)) return null;
|
|
|
|
let best = null;
|
|
let bestRank = Infinity;
|
|
for (const entry of entries) {
|
|
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) continue;
|
|
if (typeof entry.path !== 'string') continue;
|
|
if (entry.path.includes('\0') || !path.isAbsolute(entry.path)) continue;
|
|
const registeredPath = canonicalize(entry.path);
|
|
if (!registeredPath) continue;
|
|
const rank = repoPaths.findIndex((repoPath) => samePath(repoPath, registeredPath));
|
|
if (rank === -1) continue;
|
|
const storagePath = resolveEntryStoragePath(entry);
|
|
if (!storagePath) continue;
|
|
const repositoryLocal = samePath(
|
|
canonicalize(path.join(entry.path, GITNEXUS_DIR)),
|
|
canonicalize(storagePath),
|
|
);
|
|
const ownershipMetadata = readIndexMetadata(storagePath);
|
|
if (!isOwnedStorage(entry.path, storagePath, repositoryLocal, ownershipMetadata)) continue;
|
|
const branchIsIndexed =
|
|
branch &&
|
|
Array.isArray(entry.branches) &&
|
|
entry.branches.some((summary) => summary && summary.branch === branch);
|
|
const indexDir = branchIsIndexed
|
|
? path.join(storagePath, BRANCHES_DIRECTORY, branchSlug(branch))
|
|
: storagePath;
|
|
const indexMetadata = branchIsIndexed ? readIndexMetadata(indexDir) : ownershipMetadata;
|
|
const lbugPath = resolveGraphPath(indexDir, indexMetadata);
|
|
if (rank < bestRank) {
|
|
bestRank = rank;
|
|
best = {
|
|
path: entry.path,
|
|
storagePath,
|
|
lbugPath,
|
|
metadata: indexMetadata,
|
|
};
|
|
}
|
|
}
|
|
return best;
|
|
}
|
|
|
|
/**
|
|
* Registry row wins (including persisted external storagePath); local owned is fallback.
|
|
* `spawnCwd` is where git is started from, when that must not be `cwd` itself.
|
|
*/
|
|
function resolveHookRepo(cwd, spawnCwd = cwd) {
|
|
const repo = findRegisteredRepo(cwd, spawnCwd) || findLocalOwnedRepo(cwd, spawnCwd);
|
|
// A matching owned registry row blocks fallback even when its graph is invalid.
|
|
return repo && repo.lbugPath ? repo : null;
|
|
}
|
|
|
|
module.exports = {
|
|
findRegisteredRepo,
|
|
findLocalOwnedRepo,
|
|
resolveHookRepo,
|
|
INDEX_METADATA_FILE,
|
|
LEGACY_METADATA_FILE,
|
|
LBUG_DIRECTORY,
|
|
};
|