Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(cli): keep -x excludes when init customize asks for patterns (#4061)

Ganesh Mf2545cd06866
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/_questions.py b/packages/cli/src/repowise/cli/commands/init_cmd/_questions.py
index 42f8e7361..9334ac9fc 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/_questions.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/_questions.py
@@ -97,7 +97,9 @@ def _apply_advanced_answers(run: InitRun, adv: dict[str, Any]) -> None:
"follow_renames": adv["follow_renames"],
"skip_tests": adv["skip_tests"],
"skip_infra": adv["skip_infra"],
- "exclude": adv["exclude"],
+ # Merge with the command-line -x patterns rather than replacing them,
+ # keeping order and dropping duplicates (same as the workspace path).
+ "exclude": tuple(dict.fromkeys((*opts.exclude, *adv["exclude"]))),
"include_submodules": adv.get("include_submodules", opts.include_submodules),
"run_mode": adv.get("run_mode", opts.run_mode),
# Asked in both branches: an index-only run renders a wiki too, and
diff --git a/tests/unit/cli/test_init_noninteractive.py b/tests/unit/cli/test_init_noninteractive.py
index 98f0bc5d7..635f6fd17 100644
--- a/tests/unit/cli/test_init_noninteractive.py
+++ b/tests/unit/cli/test_init_noninteractive.py
@@ -378,3 +378,66 @@ class TestNonInteractiveKeyPersistence:
written = (tmp_path / ".repowise" / ".env").read_text(encoding="utf-8")
assert "OPENAI_API_KEY=sk-newline\n" in written
+
+
+class TestAdvancedExcludeMergesWithFlag:
+ """Customize answers must add to `-x` patterns, not replace them (issue #4034)."""
+
+ @staticmethod
+ def _exclude_patterns(tmp_path, args, typed):
+ import subprocess
+ from unittest import mock
+
+ from repowise.cli.commands.init_cmd import _prepare, _questions
+
+ repo = tmp_path / "repo"
+ (repo / "vendor").mkdir(parents=True)
+ (repo / "vendor" / "lib.py").write_text("x = 1\n")
+ subprocess.run(["git", "init", "-q", str(repo)], check=True)
+
+ answers = {
+ "commit_limit": 5000,
+ "follow_renames": False,
+ "skip_tests": False,
+ "skip_infra": False,
+ "exclude": typed,
+ "run_mode": "standard",
+ "max_file_pages": None,
+ "generate_docs": False,
+ }
+ seen: list[list[str]] = []
+
+ def _stop_after_settings(run):
+ seen.append(list(run.exclude_patterns))
+ return False
+
+ with (
+ mock.patch.object(_prepare, "_interactive_gate", lambda **_: True),
+ mock.patch.object(_questions, "interactive_mode_select", lambda _c: "advanced"),
+ mock.patch.object(_questions, "interactive_generate_docs_toggle", lambda _c: False),
+ mock.patch.object(
+ _questions, "interactive_advanced_config", lambda *a, **k: dict(answers)
+ ),
+ mock.patch.object(_prepare, "_confirm_wiki_overwrite", _stop_after_settings),
+ ):
+ result = CliRunner().invoke(cli, ["init", str(repo), *args])
+
+ assert result.exit_code == 0, result.output
+ assert seen, result.output
+ return seen[0]
+
+ def test_typed_pattern_is_added_after_flag(self, tmp_path):
+ got = self._exclude_patterns(tmp_path, ["-x", "vendor/"], ("build/",))
+ assert got == ["vendor/", "build/"]
+
+ def test_enter_keeps_flag_patterns(self, tmp_path):
+ got = self._exclude_patterns(tmp_path, ["-x", "vendor/"], ())
+ assert got == ["vendor/"]
+
+ def test_repeated_pattern_is_not_duplicated(self, tmp_path):
+ got = self._exclude_patterns(tmp_path, ["-x", "vendor/"], ("vendor/",))
+ assert got == ["vendor/"]
+
+ def test_no_flag_uses_typed_patterns(self, tmp_path):
+ got = self._exclude_patterns(tmp_path, [], ("build/",))
+ assert got == ["build/"]