Fixing "ref HEAD is not a symbolic ref" error; logging enhancements
This addresses the following issues:
- "ref HEAD is not a symbolic ref" fatal error, see https://github.com/bk201-/jira-prepare-commit-msg/issues/534
- unresolved and outdated ESLint dependencies
- enhancing logging
During its operations, jira-prepare-commit-msg used this command to determine the branch name to work on:
$ git symbolic-ref --short HEAD
Unfortunately it doesn't work for rebases and just throws the fatal error: "ref HEAD is not a symbolic ref"
Note that we barely want to rewrite a bunch of previous commits when rebase, don't we? So ideally we should skip running the hook, but we can't. There is no way to figure out from our .husky/prepare-commit-msg script if it's a rebase or a regular commit.
One solution is to use another command to detect branch name:
$ git rev-parse -abbrev-ref HEAD
because it doesn't crash and seems to be returning the same "HEAD" string for rebase commits. So we can detect that and silently exit not trying to interfere in the middle of a rebase.
Now about logging.
We don't really need to see all those "start" and "done" messages. The only thing we might want to see is the new rewritten commit message. And that one was not displayed. Fixed it.
Example
Was:
(sx-1234-foo +$)$ git commit -m t21 -n
JIRA prepare commit msg > start
JIRA prepare commit msg > The JIRA ticket ID is: SX-1234
JIRA prepare commit msg > done
[sx-1234-foo 45c76d7a] SX-1234: t21
1 file changed, 1 insertion(+), 1 deletion(-)
Became:
(sx-1234-foo +$)$ git commit -m t22 -n
JIRA prepare commit msg > Rewriting commit message to "SX-1234: t22"
[sx-1234-foo 36e9111b] SX-1234: t22
1 file changed, 1 insertion(+), 1 deletion(-)
hello?