:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(hogli): scope ci:preflight --strict to committed diff (#69014)
Raúl Negrón-Otero9e39d33b5d9b
diff --git a/tools/hogli-commands/hogli_commands/change_detection.py b/tools/hogli-commands/hogli_commands/change_detection.pyindex 87e55e47fec9..919f72c357d3 100644--- a/tools/hogli-commands/hogli_commands/change_detection.py+++ b/tools/hogli-commands/hogli_commands/change_detection.py@@ -20,7 +20,7 @@ def _git(*args: str) -> subprocess.CompletedProcess[str]:return subprocess.run(["git", *args], cwd=REPO_ROOT, capture_output=True, text=True)-def changed_files(against: str | None = None) -> list[str]:+def changed_files(against: str | None = None, *, include_worktree: bool = True) -> list[str]:"""Files the branch touches vs a base ref (merge-base), plus uncommitted/untracked work.An explicit *against* raises on a bad ref so a typo can't masquerade as a clean@@ -29,6 +29,11 @@ def changed_files(against: str | None = None) -> list[str]:working-tree-only detection when neither exists (single-branch clones, baresandboxes). ``-z`` output keeps paths with spaces/non-ASCII unquoted, and``--untracked-files=all`` lists files inside brand-new directories.++ ``include_worktree=False`` restricts the result to the committed branch diff,+ dropping uncommitted and untracked work — the correct scope for a pre-push gate,+ where only committed changes are actually pushed (and can reach CI). Callers that+ iterate on local edits (``build``, ``test --changed``) keep the default."""files: set[str] = set()for base in [against] if against is not None else ["origin/master", "master"]:@@ -38,6 +43,8 @@ def changed_files(against: str | None = None) -> list[str]:breakif against is not None:raise click.UsageError(f"git diff against {against!r} failed: {diff.stderr.strip()}")+ if not include_worktree:+ return sorted(files)status = _git("status", "--porcelain", "-z", "--no-renames", "--untracked-files=all")if status.returncode != 0:# A failed status (e.g. index.lock contention) must not read as "no uncommitted work".diff --git a/tools/hogli-commands/hogli_commands/ci_preflight.py b/tools/hogli-commands/hogli_commands/ci_preflight.pyindex 6fcdb3579ba7..de82c61d7593 100644--- a/tools/hogli-commands/hogli_commands/ci_preflight.py+++ b/tools/hogli-commands/hogli_commands/ci_preflight.py@@ -424,7 +424,11 @@ def ci_preflight(do_fix: bool, strict: bool, against: str | None, as_json: bool)# Fetch first so both the diff base and the staleness check see a fresh# origin/master — a stale local ref would inflate the diff with master's own commits._fetch_master()- files = changed_files(against)+ # --strict is the blocking pre-push hook: scope it to the committed diff, since a+ # push only carries commits. Untracked/uncommitted work never reaches CI, so gating+ # a push on lint errors in a scratch file is a false block. Advisory/--fix runs keep+ # the working tree in scope so agents can clean edits before committing.+ files = changed_files(against, include_worktree=not strict)base = against or "origin/master"triggered: list[DiffCheck] = []diff --git a/tools/hogli-commands/hogli_commands/tests/test_change_detection.py b/tools/hogli-commands/hogli_commands/tests/test_change_detection.pyindex 723fce8caa6f..1147861d6df0 100644--- a/tools/hogli-commands/hogli_commands/tests/test_change_detection.py+++ b/tools/hogli-commands/hogli_commands/tests/test_change_detection.py@@ -57,6 +57,14 @@ class TestChangedFiles:with pytest.raises(click.UsageError):changed_files("orgin/master")+ @patch("hogli_commands.change_detection.subprocess.run")+ def test_exclude_worktree_returns_committed_diff_only(self, mock_run: MagicMock) -> None:+ # Pre-push scope: only the committed branch diff is pushed, so untracked/uncommitted+ # work must not leak in. git status is never consulted (a single subprocess call).+ mock_run.side_effect = [_completed(stdout="file_branch.py\0")]+ assert changed_files(include_worktree=False) == ["file_branch.py"]+ assert mock_run.call_count == 1+@patch("hogli_commands.change_detection.subprocess.run")def test_status_failure_raises_instead_of_dropping_uncommitted_work(self, mock_run: MagicMock) -> None:mock_run.side_effect = [