Skip to content

Commit 57e7a20

Browse files
authored
chore: no longer automatically trigger init by ccc index (#82)
1 parent 3adffb3 commit 57e7a20

4 files changed

Lines changed: 7 additions & 77 deletions

File tree

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,5 @@ htmlcov/
4444
# Generated version file
4545
src/cocoindex_code/_version.py
4646

47-
# CocoIndex
48-
.cocoindex_code/
4947
# CocoIndex Code (ccc)
5048
/.cocoindex_code/

src/cocoindex_code/cli.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -209,35 +209,6 @@ def remove_from_gitignore(project_root: Path) -> None:
209209
gitignore.write_text("".join(new_lines))
210210

211211

212-
def auto_init_project() -> Path:
213-
"""Auto-initialize project from CWD.
214-
215-
Runs core ``init`` logic without parent-directory confirmation and without
216-
the "run ``ccc index``" prompt. Returns the project root (CWD).
217-
"""
218-
from .settings import project_settings_path
219-
220-
cwd = Path.cwd().resolve()
221-
settings_file = project_settings_path(cwd)
222-
223-
if not settings_file.is_file():
224-
# Create user settings if missing
225-
user_path = user_settings_path()
226-
if not user_path.is_file():
227-
save_user_settings(default_user_settings())
228-
_typer.echo(f"Created user settings: {user_path}")
229-
230-
# Create project settings
231-
save_project_settings(cwd, default_project_settings())
232-
_typer.echo(f"Created project settings: {settings_file}")
233-
_typer.echo("You can edit the settings files to customize indexing behavior.")
234-
235-
# Update .gitignore
236-
add_to_gitignore(cwd)
237-
238-
return cwd
239-
240-
241212
# ---------------------------------------------------------------------------
242213
# Commands
243214
# ---------------------------------------------------------------------------
@@ -289,19 +260,7 @@ def init(
289260
@app.command()
290261
def index() -> None:
291262
"""Create/update index for the codebase."""
292-
from .client import ensure_daemon
293-
294-
# Auto-init if not in an initialized project
295-
root = find_project_root(Path.cwd())
296-
if root is None:
297-
root = auto_init_project()
298-
299-
try:
300-
client = ensure_daemon()
301-
except Exception as e:
302-
_typer.echo(f"Error: Failed to connect to daemon: {e}", err=True)
303-
raise _typer.Exit(code=1)
304-
project_root = str(root)
263+
client, project_root = require_daemon_for_project()
305264

306265
_run_index_with_progress(client, project_root)
307266

tests/test_cli_helpers.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from cocoindex_code.cli import (
1010
add_to_gitignore,
11-
auto_init_project,
1211
remove_from_gitignore,
1312
require_project_root,
1413
resolve_default_path,
@@ -126,24 +125,3 @@ def test_remove_from_gitignore_no_entry(tmp_path: Path) -> None:
126125
gitignore.write_text(original)
127126
remove_from_gitignore(tmp_path)
128127
assert gitignore.read_text() == original
129-
130-
131-
def test_auto_init_project(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
132-
(tmp_path / ".git").mkdir()
133-
monkeypatch.chdir(tmp_path)
134-
# Monkeypatch user settings dir to avoid touching real home
135-
monkeypatch.setattr(
136-
"cocoindex_code.cli.user_settings_path",
137-
lambda: tmp_path / ".cocoindex_code_user" / "global_settings.yml",
138-
)
139-
monkeypatch.setattr(
140-
"cocoindex_code.settings.user_settings_dir",
141-
lambda: tmp_path / ".cocoindex_code_user",
142-
)
143-
144-
result = auto_init_project()
145-
146-
assert result == tmp_path
147-
assert (tmp_path / ".cocoindex_code" / "settings.yml").is_file()
148-
assert (tmp_path / ".gitignore").is_file()
149-
assert "/.cocoindex_code/" in (tmp_path / ".gitignore").read_text()

tests/test_e2e.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,12 @@ def test_session_search_refresh() -> None:
381381
assert "main.py" in result.output
382382

383383

384-
def test_session_index_auto_init(e2e_project: Path) -> None:
385-
"""Running ``ccc index`` from uninitialized dir auto-inits, then search works."""
386-
# Do NOT call init — just run index directly
387-
result = runner.invoke(app, ["index"], catch_exceptions=False)
388-
assert result.exit_code == 0, result.output
389-
assert (e2e_project / ".cocoindex_code" / "settings.yml").exists()
390-
391-
# Search should work
392-
result = runner.invoke(app, ["search", "fibonacci"], catch_exceptions=False)
393-
assert result.exit_code == 0
394-
assert "main.py" in result.output
384+
@pytest.mark.usefixtures("e2e_project")
385+
def test_session_index_not_initialized_errors() -> None:
386+
"""Running ``ccc index`` from uninitialized dir should error."""
387+
result = runner.invoke(app, ["index"])
388+
assert result.exit_code != 0
389+
assert "ccc init" in result.output
395390

396391

397392
def test_session_subdirectory_path_default(e2e_project: Path) -> None:

0 commit comments

Comments
 (0)