-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
pre-merge-commit hook not triggering #1494
Comments
Hi, Try running with |
Hi, below is the output result of my use of
|
Thanks for the logs. Here it fails to find
But here, it finds
Check that there's no typo in your prepare-commit-msg file name. |
Thank you for your reply. However, I do not use the Even after creating this file, the Below is the new log:
|
My bad I misread. Can you try this: cp .husky/_/pre-commit .husky/_/pre-merge-commit
# ensure that you have .husky/pre-merge-commit as well with your code And retry your merge. Please let me know if it works. |
Hello, thank you for your reply. The Here is a more comprehensive workaround until a permanent fix is implemented:
const fs = require('fs');
const path = require('path');
// Specify the directory and file name you want to create
const directoryPath = path.join(__dirname, './.husky/_');
const filePath = path.join(directoryPath, 'pre-merge-commit');
// Check if the file already exists, if it does, do not create it
if (fs.existsSync(filePath)) {
console.log(`pre-merge-commit git hook file already exists at ${filePath}`);
return;
}
// Ensure the directory exists, if not, create it
if (!fs.existsSync(directoryPath)) {
fs.mkdirSync(directoryPath, { recursive: true });
}
const fileContent = `#!/usr/bin/env sh
. "$(dirname "$0")/h"`;
// Create the file and write the content (if the file does not exist)
fs.writeFileSync(filePath, fileContent, { flag: 'w' });
// Set the file permissions to -rwxr-xr-x
fs.chmodSync(filePath, 0o755);
console.log(`pre-merge-commit git hook file has been created at ${filePath}`);
"scripts": {
"prepare": "husky"
}, Change it to: "scripts": {
"prepare": "husky && node createHook.js"
},
|
Do you want to make the fix? Just add the missing hook after |
support pre-merge-commit hook fixes: typicode#1494
Sure, I've already made the fix and submitted a pull request. You can check and review it here: #1497. |
I've set up a
pre-merge-commit
hook using Husky, but it doesn't seem to be triggering when I perform a merge. Here are the details:Steps to Reproduce:
Expected Behavior:
The
pre-merge-commit
hook should trigger and display the messagepre-merge-commit hook triggered
before the merge is completed.Actual Behavior:
The
pre-merge-commit
hook is not triggered at all, and the merge process continues without any output from the hook.Environment:
Husky Version: ^9.1.4
Node Version: 20.8.0
Git Version: 2.46.0
Operating System: MacOS Sonoma 14.0
Additional Context:
Workaround
There is a workaround to fix this issue by manually adding a
pre-merge-commit
file in the./husky/_
directory with the following content:After ensuring the file is executable, the issue is resolved. However, when the
_
directory is deleted and Husky is re-initialized using thenpm run prepare
command, the pre-merge-commit file is not generated. This defeats the purpose of using Husky, as the hook needs to be manually recreated each time.The text was updated successfully, but these errors were encountered: