Force re-index by deleting and rebuilding the repository.
(path: str, context: Optional[str] = None, no_progress: bool = False)
| 858 | |
| 859 | |
| 860 | def reindex_helper(path: str, context: Optional[str] = None, no_progress: bool = False): |
| 861 | """Force re-index by deleting and rebuilding the repository.""" |
| 862 | time_start = time.time() |
| 863 | path_obj = Path(path).resolve() |
| 864 | index_cwd = path_obj if path_obj.is_dir() else path_obj.parent |
| 865 | services = _initialize_services(context, cwd=index_cwd) |
| 866 | if not all(services[:3]): |
| 867 | _fail_services_init() |
| 868 | |
| 869 | db_manager, graph_builder, code_finder, ctx = services |
| 870 | |
| 871 | if not path_obj.exists(): |
| 872 | console.print(f"[red]Error: Path does not exist: {path_obj}[/red]") |
| 873 | db_manager.close_driver() |
| 874 | raise typer.Exit(code=1) |
| 875 | |
| 876 | # Check if already indexed |
| 877 | indexed_repos = code_finder.list_indexed_repositories() |
| 878 | repo_exists = any_repo_matches_path(indexed_repos, path_obj) |
| 879 | |
| 880 | if repo_exists: |
| 881 | console.print(f"[yellow]Deleting existing index for: {path_obj}[/yellow]") |
| 882 | try: |
| 883 | graph_builder.delete_repository_from_graph(str(path_obj)) |
| 884 | console.print("[green]✓[/green] Deleted old index") |
| 885 | except Exception as e: |
| 886 | console.print(f"[red]Error deleting old index: {e}[/red]") |
| 887 | db_manager.close_driver() |
| 888 | raise typer.Exit(code=1) |
| 889 | |
| 890 | console.print(f"[cyan]Re-indexing: {path_obj}[/cyan]") |
| 891 | |
| 892 | try: |
| 893 | asyncio.run(_run_index_with_progress(graph_builder, path_obj, is_dependency=False, cgcignore_path=ctx.cgcignore_path, disable_progress=no_progress)) |
| 894 | time_end = time.time() |
| 895 | elapsed = time_end - time_start |
| 896 | _print_call_resolution_diagnostics(graph_builder) |
| 897 | _print_index_execution_summary(graph_builder) |
| 898 | console.print(f"[green]Successfully re-indexed: {path} in {elapsed:.2f} seconds[/green]") |
| 899 | except Exception as e: |
| 900 | console.print(f"[bold red]An error occurred during re-indexing:[/bold red] {e}") |
| 901 | raise typer.Exit(code=1) |
| 902 | finally: |
| 903 | db_manager.close_driver() |
| 904 | |
| 905 | |
| 906 | def update_helper(path: str, context: Optional[str] = None, quiet: bool = False): |
no test coverage detected