diff --git a/gitnexus/src/cli/index-repo.ts b/gitnexus/src/cli/index-repo.ts index 26bb0eff6..e316a036b 100644 --- a/gitnexus/src/cli/index-repo.ts +++ b/gitnexus/src/cli/index-repo.ts @@ -20,6 +20,7 @@ import { getGitRoot, isGitRepo } from "../storage/git.js"; export interface IndexOptions { force?: boolean; + allowNonGit?: boolean; } export const indexCommand = async ( @@ -45,9 +46,10 @@ export const indexCommand = async ( repoPath = gitRoot; } - if (!isGitRepo(repoPath)) { + if (!options?.allowNonGit && !isGitRepo(repoPath)) { console.log(` Not a git repository: ${repoPath}`); console.log(" Initialize one with `git init` or choose a valid repo path.\n"); + console.log(" Or use --allow-non-git to register an existing .gitnexus index anyway.\n"); process.exitCode = 1; return; } @@ -116,4 +118,4 @@ export const indexCommand = async ( console.log(` ${repoPath}`); console.log(""); -}; +}; \ No newline at end of file diff --git a/gitnexus/src/cli/index.ts b/gitnexus/src/cli/index.ts index f798b7756..ca9443d73 100644 --- a/gitnexus/src/cli/index.ts +++ b/gitnexus/src/cli/index.ts @@ -36,6 +36,7 @@ program .command('index [path...]') .description('Register an existing .gitnexus/ folder into the global registry (no re-analysis needed)') .option('-f, --force', 'Register even if meta.json is missing (stats will be empty)') + .option('--allow-non-git', 'Allow registering folders that are not Git repositories') .action(createLazyAction(() => import('./index-repo.js'), 'indexCommand')); program diff --git a/gitnexus/test/unit/index-repo-command.test.ts b/gitnexus/test/unit/index-repo-command.test.ts index d8cba675a..63f502006 100644 --- a/gitnexus/test/unit/index-repo-command.test.ts +++ b/gitnexus/test/unit/index-repo-command.test.ts @@ -126,4 +126,14 @@ describe('indexCommand', () => { ); expect(process.exitCode).toBeUndefined(); }); + + it('registers non-git path when --allow-non-git is set', async () => { + mockIsGitRepo.mockReturnValue(false); + + const { indexCommand } = await import('../../src/cli/index-repo.js'); + await indexCommand(['/outside/path'], { allowNonGit: true }); + + expect(mockRegisterRepo).toHaveBeenCalledTimes(1); + expect(process.exitCode).toBeUndefined(); + }); });