Skip to content

Fixing "ref HEAD is not a symbolic ref" error; logging enhancements#748

Open
OnkelTem wants to merge 1 commit intobk201-:masterfrom
OnkelTem:issue-534
Open

Fixing "ref HEAD is not a symbolic ref" error; logging enhancements#748
OnkelTem wants to merge 1 commit intobk201-:masterfrom
OnkelTem:issue-534

Conversation

@OnkelTem
Copy link
Copy Markdown
Contributor

@OnkelTem OnkelTem commented Oct 8, 2024

This addresses the following issues:

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

@OnkelTem
Copy link
Copy Markdown
Contributor Author

hello?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant