maiao icon indicating copy to clipboard operation
maiao copied to clipboard

maiao conflicts with husky / pre-commit or pre-push rules

Open jonathanloske opened this issue 2 years ago • 3 comments

Continued from an Adevinta-internal Slack discussion: https://adevinta.slack.com/archives/C018Q6DJNCD/p1700139366823739

Problem description: When running maiao inside a yarn-based repository with pre-commit and pre-push hooks from husky, it fails with the following error: fatal: It seems that there is already a rebase-merge directory, and I wonder if you are in the middle of another rebase. If that is the case, please try [...]. I am not in the middle of a rebase and don't know why the message appears so I can't continue. The tools do the following:

pre-commit runs linting:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged

pre-push runs TypeScript compile check (tsc --noEmit), unit tests (yarn test -- --coverage) and E2E Cypress tests (start-server-and-test dev http://localhost:3000/internal/ping cypress:local:headless):

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn ts:check
yarn test:coverage
yarn e2e:local:headless

Next step to check: removing the individual hook steps one-by-one to see if we can narrow it down to one step or if husky in general is responsible. Will report back here.

jonathanloske avatar Nov 16 '23 15:11 jonathanloske

I think I have the missing piece of the puzzle. husky changes git config core.hooksPath and sets it to .husky so it can run its own hooks. maiao sets up a Gerrit hook in .git/hooks/commit-msg that is not run anymore when husky is used. I tried combining our commit-msg hook with the one from .git/hooks/commit-msg but then I can't commit anymore. But when I do my normal commits with git config core.hooksPath set to husky and then change git config core.hooksPath to point to .git/hooks before running git review, everything works. So maiao could check what git config core.hooksPath is set to and temporarily change it to .git/hooks while running and at the end change it back to whatever it was set to before.

jonathanloske avatar Nov 16 '23 17:11 jonathanloske

Thanks for your input.

We didn't have the time to look at it yet, but will try to reproduce it locally to see how we can provide a solution for those cases.

tjamet avatar Jan 15 '24 16:01 tjamet

Hi!

The idea of the commit message is indeed to automatically add the Change-Id as soon as the commit is created. It's hence important to keep it executed every time a commit is created, so avoid useless rebases.

I could reproduce a repo with husky localy and run both the husky and the maiao commit message hooks. To do so, assuming you have your core.hooksPath set to $repoRoot/.husky, you should be able to add the following line anywhere in your commit-msg hook file to get it to work

[ -x "${0%/*}/../.git/hooks/commit-msg" ] && "${0%/*}/../.git/hooks/commit-msg" "$@"

Let me know if you need further help. Hopefully I will be able to help faster

tjamet avatar Mar 12 '24 20:03 tjamet