Skip to content

fix(content-guards): support markdown linting in git worktrees#48

Merged
JacobPEvans merged 2 commits intomainfrom
fix/validate-markdown-worktree-paths
Feb 18, 2026
Merged

fix(content-guards): support markdown linting in git worktrees#48
JacobPEvans merged 2 commits intomainfrom
fix/validate-markdown-worktree-paths

Conversation

@JacobPEvans
Copy link
Owner

@JacobPEvans JacobPEvans commented Feb 18, 2026

Summary

  • Fixes validate-markdown.sh hook to handle files in git worktrees
  • markdownlint-cli2 requires 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"
  • Fix: cd to the project root (where config was found) or the file's own directory, pass a relative path
  • Bumps content-guards to 1.0.1

Root Cause

The hook called markdownlint-cli2 "$file_path" with an absolute path. markdownlint-cli2 requires files to be relative to its CWD. When the session CWD is main/ but the edited file is in chore/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

  • Edit a .md file in a worktree sibling directory — hook should pass without error
  • Edit a .md file with real markdown errors — hook should still catch and block

🤖 Generated with Claude Code


Important

Fixes validate-markdown.sh to support markdown linting in git worktrees by using relative paths and updates content-guards to version 1.0.1.

  • Behavior:
    • Fixes validate-markdown.sh to handle markdown files in git worktrees by using relative paths.
    • Changes directory to project root or file's directory before running markdownlint-cli2.
  • Version:
    • Bumps content-guards version to 1.0.1 in plugin.json.

This description was created by Ellipsis for 3623fb8. You can customize this summary. It will automatically update as commits are pushed.

…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>
Copilot AI review requested due to automatic review settings February 18, 2026 06:52
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 3623fb8 in 7 seconds. Click for details.
  • Reviewed 44 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft 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 Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 markdownlint-cli2, the validate-markdown.sh hook now properly processes files regardless of their location within a worktree, ensuring consistent code quality checks. The plugin version has also been updated to 1.0.1.

Highlights

  • Git Worktree Support: The validate-markdown.sh hook has been updated to correctly handle markdown files located within git worktrees, resolving issues where markdownlint-cli2 failed due to incorrect path resolution.
  • Markdown Linting Logic: Modified the validate-markdown.sh script to change its current working directory (cd) to either the project root (if a config is found) or the file's own directory before executing markdownlint-cli2, ensuring relative paths are used as required by the linter.
  • Version Bump: The content-guards plugin version has been incremented from 1.0.0 to 1.0.1 to reflect these changes.
Changelog
  • content-guards/.claude-plugin/plugin.json
    • Updated the plugin version from 1.0.0 to 1.0.1.
  • content-guards/scripts/validate-markdown.sh
    • Refactored the markdownlint-cli2 execution logic to cd into the appropriate directory ($search_dir or dirname -- "$file_path") before running the linter.
    • Calculated a relative path (lint_file) for markdownlint-cli2 based on the new current working directory.
    • Removed the conditional if [[ ${#config_flag[@]} -gt 0 ]] block, unifying the linting execution path.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.sh to use relative paths by cd'ing to the appropriate directory before running markdownlint-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>
@JacobPEvans JacobPEvans merged commit 8cbf6a1 into main Feb 18, 2026
5 checks passed
@JacobPEvans JacobPEvans deleted the fix/validate-markdown-worktree-paths branch February 18, 2026 10:35
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.

1 participant

Comments