jira-prepare-commit-msg icon indicating copy to clipboard operation
jira-prepare-commit-msg copied to clipboard

Unable to read the file ".git/COMMIT_EDITMSG"

Open adamtay opened this issue 4 years ago • 2 comments

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".

adamtay avatar Jun 24 '21 01:06 adamtay

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);

adamtay avatar Jun 24 '21 02:06 adamtay

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.

rishitank avatar May 05 '22 17:05 rishitank