Repository navigation
fix(args): scope --workdir to its directory on Windows - #1657
Merged
Merged
Conversation
On Windows, `--workdir <dir>` did not limit the changelog to that directory. `fs::canonicalize` returns a `\\?\` verbatim path there, which never starts with the repository root reported by git, so no include pattern was added and every commit was kept. Canonicalize the root as well before stripping it. Build the pattern from the path components joined with `/`, since git diff paths always use `/` and only a trailing `/` makes the pattern expand to `**`. Otherwise the pattern would be `sub\dir\` and match nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1657 +/- ##
==========================================
+ Coverage 53.21% 53.36% +0.15%
==========================================
Files 28 28
Lines 2633 2639 +6
==========================================
+ Hits 1401 1408 +7
+ Misses 1232 1231 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Congrats on merging your first pull request! ⛰️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Windows,
git cliff --workdir <subdir>doesn't scope the changelog to that directory; every commit in the repository is listed.Two things go wrong in the include pattern built from
--workdir(added in #1627):fs::canonicalizereturns a\?\C:\...verbatim path on Windows, while the repository root reported by libgit2 is a plainC:/...path.strip_prefixfails, so no include pattern is added at all.to_string_lossy(), which givessub\dir\.normalize_patternonly appends**after a trailing/(since fix(git): match directory include/exclude patterns on Windows #1593), and git diff paths always use/, so the pattern would match nothing and the changelog would be empty.This moves the logic into a small
workdir_include_patternhelper that canonicalizes both the root and the workdir, and builds the pattern from the path components joined with/. On Linux and macOS the resulting pattern is the same as before.#1379 also canonicalizes paths, but it still builds the pattern with
to_string_lossy(), so it wouldn't cover the second part.Motivation and Context
Repository with three commits, only one touching
sub/:Before (Windows): all three commits are listed. After: only the commit that touches
sub/.--workdir .still lists everything, and running from insidesub/without--workdiris unchanged.How Has This Been Tested?
Added two unit tests for
workdir_include_pattern. On Windows,workdir_include_pattern_is_repo_relative_with_forward_slashesfails without the change and passes with it.cargo test -p git-cliffpasses on Windows 11 (x86_64-pc-windows-gnu), and the repository above gives the output described. The test job runs on Linux only, where the test passes both before and after.Types of Changes
Checklist:
cargo +nightly fmt --allcargo clippy --tests --verbose -- -D warningscargo testI used Claude Code to write this change.