Skip to content

fix(args): scope --workdir to its directory on Windows - #1657

Merged
orhun merged 2 commits into
orhun:mainfrom
b84330808:fix/windows-workdir-include-path
Oct 23, 2026
Merged

orhun merged 2 commits into
orhun:mainfrom
b84330808:fix/windows-workdir-include-path

Conversation

@b84330808

Copy link
Copy Markdown
Contributor

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):

  1. fs::canonicalize returns a \?\C:\... verbatim path on Windows, while the repository root reported by libgit2 is a plain C:/... path. strip_prefix fails, so no include pattern is added at all.
  2. With that fixed, the pattern is built with to_string_lossy(), which gives sub\dir\. normalize_pattern only 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_pattern helper 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/:

git cliff --workdir sub

Before (Windows): all three commits are listed. After: only the commit that touches sub/. --workdir . still lists everything, and running from inside sub/ without --workdir is unchanged.

How Has This Been Tested?

Added two unit tests for workdir_include_pattern. On Windows, workdir_include_pattern_is_repo_relative_with_forward_slashes fails without the change and passes with it. cargo test -p git-cliff passes 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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly (if applicable).
  • I have formatted the code with rustfmt.
    • cargo +nightly fmt --all
  • I checked the lints with clippy.
    • cargo clippy --tests --verbose -- -D warnings
  • I have added tests to cover my changes.
  • All new and existing tests passed.
    • cargo test

I used Claude Code to write this change.

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]>
@b84330808
b84330808 requested a review from orhun as a code owner October 23, 2026 17:04
@codecov-commenter

codecov-commenter commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.36%. Comparing base (60e0be9) to head (60afd03).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
git-cliff/src/lib.rs 61.54% 5 Missing ⚠️
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     
Flag Coverage Δ
unit-tests 53.36% <61.54%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@orhun orhun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@orhun
orhun merged commit 82ba45e into orhun:main Oct 23, 2026
112 of 116 checks passed
@welcome

welcome Bot commented Oct 23, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! ⛰️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants