fix(content-guards): support markdown linting in git worktrees#48
fix(content-guards): support markdown linting in git worktrees#48JacobPEvans merged 2 commits intomainfrom
Conversation
…rt worktrees markdownlint-cli2 requires the target file path to be within its working directory. When editing files in git worktrees (which live at sibling paths like chore/my-branch/ rather than under main/), the absolute path passed to the linter fails with "Path is not in cwd". Fix: determine the lint working directory (project root when config found, or the file's own directory), strip the prefix to get a relative path, and cd into that directory before invoking markdownlint-cli2. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 3623fb8 in 7 seconds. Click for details.
- Reviewed
44lines of code in2files - Skipped
0files when reviewing. - Skipped posting
0draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
Workflow ID: wflow_5FkQBTIY68DJMFht
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Summary of ChangesHello @JacobPEvans, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue preventing markdown linting from functioning correctly within git worktrees. By adjusting the execution context for Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue where markdown linting would fail within git worktrees due to how paths were being handled. The solution of changing the directory and using a relative path is appropriate and well-implemented. The change also nicely refactors the script to remove some duplicated code. The provided suggestion to improve error handling is valid and aligns with good shell scripting practices, including correctly quoting array expansions. Otherwise, the changes look good.
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the validate-markdown.sh hook that prevented it from working correctly with git worktrees. The issue occurred because markdownlint-cli2 requires files to be relative to its working directory, but the hook was passing absolute paths from worktree directories. The fix changes the working directory to either the config directory (when project config is found) or the file's directory (when using fallback config), and passes a relative path to the linter.
Changes:
- Modified path handling in
validate-markdown.shto use relative paths by cd'ing to the appropriate directory before runningmarkdownlint-cli2 - Bumped plugin version from 1.0.0 to 1.0.1 (appropriate patch version for a bug fix)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| content-guards/scripts/validate-markdown.sh | Refactored to determine lint_dir (config dir or file dir), compute relative path, and run markdownlint-cli2 from that directory |
| content-guards/.claude-plugin/plugin.json | Version bump to 1.0.1 for the bug fix release |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fix comment: "project root" -> "config directory" (search_dir may be a subdir)
- Guard lint_file path stripping when lint_dir is "/" to avoid "//" prefix mismatch
- Group cd + markdownlint in { } subshell so cd errors are captured in markdownlint_output
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
validate-markdown.shhook to handle files in git worktreesmarkdownlint-cli2requires the target file to be within its working directory; absolute paths from worktrees (e.g.chore/my-branch/) fail with "Path is not in cwd"content-guardsto1.0.1Root Cause
The hook called
markdownlint-cli2 "$file_path"with an absolute path.markdownlint-cli2requires files to be relative to its CWD. When the session CWD ismain/but the edited file is inchore/my-worktree/, the tool throws an uncaught exception and exits non-zero — causing a spurious blocking error even when the markdown is perfectly valid.Test plan
.mdfile in a worktree sibling directory — hook should pass without error.mdfile with real markdown errors — hook should still catch and block🤖 Generated with Claude Code
Important
Fixes
validate-markdown.shto support markdown linting in git worktrees by using relative paths and updatescontent-guardsto version1.0.1.validate-markdown.shto handle markdown files in git worktrees by using relative paths.markdownlint-cli2.content-guardsversion to1.0.1inplugin.json.This description was created by
for 3623fb8. You can customize this summary. It will automatically update as commits are pushed.