-
Notifications
You must be signed in to change notification settings - Fork 13
fix: pre-commit misc fixes #429
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
Open
regit
wants to merge
1
commit into
KeisukeYamashita:main
Choose a base branch
from
regit:fix-pre-commit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| - id: commitlint | ||
| name: Assert Conventional Commit Messages | ||
| description: 'Asserts that Conventional Commits have been used for all commit messages according to the rules for this repo.' | ||
| entry: commitlint --edit | ||
| entry: commitlint --edit .git/COMMIT_EDITMSG | ||
| language: rust | ||
| stages: [prepare-commit-msg] | ||
| stages: [commit-msg] | ||
| pass_filenames: false | ||
| require_serial: true | ||
| verbose: true | ||
| verbose: true | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
❓ Verification inconclusive
Use a dynamic commit message argument instead of a hard-coded path
Hard‑coding
.git/COMMIT_EDITMSGcan break in environments with custom Git dirs or submodules. Let pre‑commit pass the correct commit-msg file via$1and restore the default filename passing:Also update or remove
pass_filenames: falseso that the hook receives the filename as its first argument.Update commitlint hook to use the dynamic commit‐message file
Hard‑coding
.git/COMMIT_EDITMSGcan break in repos with custom Git dirs or submodules. In your.pre-commit-hooks.yaml:• File:
.pre-commit-hooks.yaml• Line: 4
Replace:
And ensure you keep:
so that pre‑commit passes only the commit‑message file (
$1) and no other filenames.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It failed when I gave the proposal a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
@regit I'll need a bit more information to help you solve this issue. Could you share what error you encountered when trying the
"$1"approach?Let me also check how the command-line arguments are processed in this project to better understand the requirements.
🏁 Script executed:
Length of output: 33
@regit Let me try different approaches to understand how the
--editflag works in this project.🏁 Script executed:
Length of output: 754
@regit Let me continue investigating to better understand how the
--editflag works.🏁 Script executed:
Length of output: 41
@regit Let me try a different approach to find how the CLI arguments are defined.
🏁 Script executed:
Length of output: 1526
@regit Let me check how the edit argument is processed, which will help understand why it's failing.
🏁 Script executed:
Length of output: 1076
@regit I understand better now. Looking at the code, I can see that the
--editflag needs a filename parameter. When you tried"$1", it likely failed because of quoting issues in the YAML file or how pre-commit passes arguments.🏁 Script executed:
Length of output: 1169
@regit I think I understand the issue now. Looking at the code, the
--editflag requires a filename argument to read the commit message from.When you tried using
"$1", it likely failed because the quotes in the YAML file were interpreted literally - pre-commit would try to runcommitlint --edit "$1"where it's looking for a file literally named$1rather than substituting the value.🏁 Script executed:
Length of output: 971
@regit I understand the issue now. When you tried using
"$1"in the YAML file, it was treated as a literal string"$1"rather than a shell variable substitution.For pre-commit hooks in the
commit-msgstage, pre-commit passes the commit message file as the first argument. To use this, you need a wrapper script approach.Here's what you could do:
Make it executable:
chmod +x pre-commit-commitlint.shUpdate your
.pre-commit-hooks.yaml:This approach properly handles the commit message file passed by pre-commit to your script.
Alternatively, if you prefer not to add a script, keeping the hardcoded
.git/COMMIT_EDITMSGpath is a reasonable compromise that works in most cases, as you've implemented in your current PR.