mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-10-30 06:42:43 +00:00
feat(cli): add --allow-non-git option to index command and update tests
This commit is contained in:
parent
340ffb0b69
commit
2e2860f3eb
3 changed files with 15 additions and 2 deletions
|
|
@ -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("");
|
||||
};
|
||||
};
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue