Skip to content

fix: do not change directory to repo-root#349

Merged
2bndy5 merged 13 commits into
mainfrom
no-chdir
Jun 11, 2026
Merged

fix: do not change directory to repo-root#349
2bndy5 merged 13 commits into
mainfrom
no-chdir

Conversation

@2bndy5

@2bndy5 2bndy5 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

ref:

Let cpp-linter stay in working directory. Instead of changing into the given --repo-root, this patch uses the value as a scope of file system focus.

  • All clang tools are invoked in the given --repo-root.
  • All discovered files are stripped of --repo-root
  • Any local caching done is prefixed with --repo-root value.

--repo-root value has always been expected as a relative path, but this should also work if given an absolute path too.

Summary by CodeRabbit

  • Bug Fixes

    • More reliable repository-root handling so file operations and tooling run consistently without changing the process working directory.
    • Cache is now stored inside the repository (under a dedicated cache folder) to avoid misplaced cache files.
  • Refactor

    • Tooling and path resolution made repo-root–relative for consistent behavior across layouts.
    • Clang tooling and suggestion generation now resolve files relative to the repo root.
  • Tests

    • Tests updated to pass repo-root explicitly instead of changing the current directory.
  • Chore

    • Bumped feedback dependency to a newer patch version.

@2bndy5 2bndy5 added the bug Something isn't working label Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.63636% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.89%. Comparing base (1089800) to head (dca82d9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cpp-linter/src/clang_tools/clang_format.rs 50.00% 4 Missing ⚠️
cpp-linter/src/clang_tools/clang_tidy.rs 80.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #349      +/-   ##
==========================================
+ Coverage   92.85%   92.89%   +0.04%     
==========================================
  Files          22       22              
  Lines        3316     3380      +64     
==========================================
+ Hits         3079     3140      +61     
- Misses        237      240       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@2bndy5

2bndy5 commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

This seemed easier than I thought it would be. Let's see what the AI review thinks...

@2bndy5 2bndy5 marked this pull request as ready for review June 10, 2026 13:08
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR threads a repo_root PathBuf through CLI params, RestClient, FileObj suggestion generation, and clang tool invocations; clang-format/tidy now run with CWD=repo_root and caches/IO use repo_root.join(CACHE_DIR) and repo_root.join(file.name) rather than relying on process CWD or a derived project cache dir.

Changes

Repository Root Path Propagation

Layer / File(s) Summary
Type contracts and API signatures
cpp-linter/src/clang_tools/mod.rs, cpp-linter/src/cli/structs.rs, cpp-linter/src/rest_client/mod.rs, cpp-linter/src/common_fs/mod.rs
Add pub const CACHE_DIR; replace ClangParams.project_cache_dir with repo_root: PathBuf; add/propagate repo_root fields and parameters; update defaults and relative database resolution; bump dependency version.
Run flow and cache setup
cpp-linter/src/run.rs
Stop changing process CWD for --repo-root; derive repo_root_path, pass it into changed-file calls and directory walking; compute cache dir at repo_root.join(CACHE_DIR) and write .gitignore there.
RestClient path relativization and suggestion wiring
cpp-linter/src/rest_client/mod.rs, cpp-linter/src/common_fs/mod.rs
Extend get_list_of_changed_files with repo_root: &Path; construct FileObj by stripping repo_root prefix when possible; thread repo_root into FileObj::make_suggestions_from_patch.
Compilation DB ingestion & clang-tools module
cpp-linter/src/clang_tools/mod.rs
Read compile_commands.json via fs::read_to_string and log+skip on read/parse failures instead of failing capture; export CACHE_DIR and add unit tests for DB parse behavior.
clang-format working directory and file resolution
cpp-linter/src/clang_tools/clang_format.rs
Set clang-format process CWD to clang_params.repo_root; compute format-patches cache at clang_params.repo_root.join(CACHE_DIR).join("patches"); read original file content from repo_root.join(&file.name); adjust pure-insertion hunk mapping.
clang-tidy working directory, parsing, and patch restore
cpp-linter/src/clang_tools/clang_tidy.rs
Refactor parse_tidy_output to take repo_root: &Path; set clang-tidy CWD to clang_params.repo_root; normalize filenames and restore patched files using repo-root-relative paths; update tests to pass PathBuf::from(".") as repo_root.
Tests and helpers
cpp-linter/tests/*, cpp-linter/src/git.rs, cpp-linter/tests/common/mod.rs
Update test helpers to accept a TempDir and pass --repo-root=<tmpdir> to run_main instead of changing process CWD; adjust temp dir creation prefix and meson command status handling.
CI / Manifest
.github/workflows/run-dev-tests.yml, cpp-linter/Cargo.toml
Update Codecov action to v7.0.0 and bump git-bot-feedback dependency to 0.5.6.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: do not change directory to repo-root' directly describes the primary change: removing the process working directory change behavior tied to the --repo-root option.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch no-chdir

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

2bndy5 added 6 commits June 10, 2026 20:27
ref:
- cpp-linter/cpp-linter#144
- cpp-linter/cpp-linter#146

Let cpp-linter stay in working directory. Instead of changing into the given `--repo-root`, this patch uses the value as a scope of file system focus.

- All clang tools are invoked in the given `--repo-root`.
- All discovered files are stripped of `--repo-root`
- Any local caching done is prefixed with `--repo-root` value.

`--repo-root` value has always been expected sa a relative path, but this should also work if given an absolute path too.
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@2bndy5 2bndy5 merged commit ead918a into main Jun 11, 2026
73 checks passed
@2bndy5 2bndy5 deleted the no-chdir branch June 11, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant