Unable to read the file ".git/COMMIT_EDITMSG"
Same as issue #11 which has been closed.
If working in a subdirectory where package.json is not at the root directory, the following error message is outputted:
JIRA prepare commit msg > Error: Unable to read the file ".git/COMMIT_EDITMSG".
The root cause of this issue is that git.getMsgFilePath() returns .git/COMMIT_EDITMSG. If husky cannot resolve the directory based on the cwd, the script errors out here message = fs.readFileSync(messageFilePath, { encoding: 'utf-8' });
As a suggestion, change git.writeJiraTicket() to do the following.
const { gitCommonDir } = gitRevParse();
const messageFilePath = getMsgFilePath().replace(".git", gitCommonDir);
I have a subfolder called client where my package.json and .jirapreparecommitmsgrc file live. I managed to fix this issue with subfolders by adding the following to my .husky/prepare-commit-msg file:
cd client/ || exit
npx jira-prepare-commit-msg "./../$1"
This way it will pick up my .jirapreparecommitmsgrc config while also being able to find .git/COMMIT_EDITMSG by using a relative path.