-
Notifications
You must be signed in to change notification settings - Fork 952
fix: add git worktree support #4591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: add git worktree support #4591
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
|
Thanks @adam-moss , for some reason the windows checks are failing. Would you mind having a look? |
|
@escapedcat looks like Windows is returning short paths. Let me handle that |
3e67fb7 to
e94aaf7
Compare
|
x_X |
e94aaf7 to
2eb5659
Compare
|
😿 |
Replace custom find-up implementation with git rev-parse --show-toplevel. This correctly handles git worktrees, submodules, and regular repositories. Also improves Windows path normalization by using resolve() before realpathSync() to handle Windows short path (8.3 format) vs long path discrepancies between Git output and Node.js filesystem APIs. Fixes conventional-changelog#787
Replace custom .git detection with git rev-parse --git-dir. This correctly resolves the git directory in worktrees where .git is a file pointing to the actual git directory.
Add comprehensive tests for git worktree support: - Test toplevel() works correctly in worktrees - Test toplevel() works from subdirectories in worktrees - Test reading edit commit message from worktree
2eb5659 to
8a3b4e8
Compare
|
😿 |
|
I'll try to get my hands on some Windows machine so I can investigate it further. Until now I was just blindly trying to fix the issue |
Thanks for trying! No rush |
User description
Summary
This PR fixes #787 by replacing custom git root detection with native git commands that properly handle git worktrees.
Problem
When running commitlint from within a git worktree directory, users get the error:
This happens because the previous implementation used
find-upto search for.gitdirectories, which doesn't work correctly with worktrees where.gitis a file pointing to the actual git directory.Solution
1.
@commitlint/top-levelfind-uplibrary withgit rev-parse --show-toplevelfind-updependency2.
@commitlint/read(get-edit-file-path).gitfile/directory detection withgit rev-parse --git-dirCOMMIT_EDITMSGlives, even in worktreesTesting
Added comprehensive tests for git worktree support:
@commitlint/top-level: 5 new tests covering regular repos, subdirectories, non-git directories, and worktrees@commitlint/read: 1 new test verifying reading commit messages from worktreesAll existing tests continue to pass.
Commits
fix(top-level): use git rev-parse for worktree support- Core implementation changefix(read): use git rev-parse --git-dir for worktree support- Edit file path fixtest: add git worktree tests for top-level and read- Test coverageFixes #787
PR Type
Bug fix
Description
Replace
find-upwith nativegit rev-parsecommands for proper worktree supportFix git root detection in
@commitlint/top-levelusinggit rev-parse --show-toplevelFix edit file path resolution in
@commitlint/readusinggit rev-parse --git-dirAdd comprehensive test coverage for git worktree scenarios
Diagram Walkthrough
File Walkthrough
index.ts
Replace find-up with git rev-parse for root detection@commitlint/top-level/src/index.ts
find-uplibrary withgit rev-parse --show-toplevelcommandundefinedfor non-git directoriesget-edit-file-path.ts
Use git rev-parse for edit file path resolution@commitlint/read/src/get-edit-file-path.ts
.gitfile/directory detection withgit rev-parse--git-dirfs.lstat()andfs.readFile()calls for simpler implementation.gitis a file pointerexecFilewith promisified async wrapper for git command executionindex.test.ts
Add comprehensive git worktree test coverage@commitlint/top-level/src/index.test.ts
and worktrees
initGitRepo()for test setupread.test.ts
Add git worktree read functionality test@commitlint/read/src/read.test.ts
operations
read()function correctly retrieves edit commit message fromworktree
tmp,fs-extra, andtinyexecfor test infrastructurepackage.json
Remove find-up, add test dependencies@commitlint/top-level/package.json
find-updependency fromdependenciesfs-extra,tmp, and their type definitions@commitlint/utilstodevDependenciessectionpackage.json
Add test utility dependencies@commitlint/read/package.json
fs-extra,tmpand their TypeScript type definitions as devdependencies