qgadrian / elixir_git_hooks

🪝 Add git hooks to Elixir projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confusion after rebuilding dependencies until git_hooks.install

dhainlin opened this issue · comments

Just a request for consideration to add some hint in the documentation should you run into unchecked dependencies errors after changes to dependencies after hooks are installed or on newly cloned repos that don't auto install hooks. For example, if you blow away deps and re-build them, you apparently need to install the git_hooks again if they use a dependency (such as credo). Not sure why this is but it is very very confusing because running a git command that triggers a pre-commit (for example) will result in something like

Unchecked dependencies for environment dev:

  • blankable (Hex package)
    the dependency is not available, run "mix deps.get"
  • ex_doc (Hex package)
    the dependency is not available, run "mix deps.get"
  • recase (Hex package)
    the dependency is not available, run "mix deps.get"
  • dialyxir (Hex package)
    the dependency is not available, run "mix deps.get"
  • credo (Hex package)
    the dependency is not available, run "mix deps.get"
    ** (Mix) Can't continue due to errors on dependencies

Re-running mix git_hooks.install will solve this issue. I found this after experimenting with latest live_view (0.18) and then trying to revert. Chased my tail re-installing hex/phoenix, clobbering deps, mix deps.clean... anyway, it wasn't until I cloned the repo on a different machine that I got the same result until I installed the git hooks.

So, this probably warrants either some research about why this happens and maybe some note in the readme. Thanks for such a useful tool.

To repro:

  1. in working repro with pre-commit hooks that use dependencies (like credo, doctor...), remove the deps folder
  2. mix do deps.get, deps.compile
  3. any git command that triggers a hook (for example the pre-commit via git commit) will fail with (Mix) Can't continue due to errors on dependencies...
  4. solved by running mix git_hooks.install again

This the same issue reported in #123 I believe

@dhainlin I believe it is.

I will link a PR with a pre-release version, can you confirm your issue gets fixed with it?

Screenshot_20221123_141150

It asks to install , whenever there is a mix command.

Just wasted a little more time than needed due to the vagueness of this error message, would be nice if it gave a hint.

I just experienced this bug while trying out this lib. Seems like the auto_install path is set to the dependency directory in the pre_commit file:

#!/bin/sh

[ "/home/cikey/projects/letest/deps/git_hooks" != "" ] && cd "/home/cikey/projects/letest/deps/git_hooks"

mix git_hooks.run pre_commit "$@"
[ $? -ne 0 ] && exit 1
exit 0

After a manual mix git_hooks.install it points to the correct path:

#!/bin/sh

[ "/home/cikey/projects/letest" != "" ] && cd "/home/cikey/projects/letest"

mix git_hooks.run pre_commit "$@"
[ $? -ne 0 ] && exit 1
exit 0

Maybe relevant: We are using an umbrella app and added this dependecy to the root mix.exs

@Cikey there is an open PR that tries to tackle this issue but needs a bit more testing before releasing it. Can you please try that branch?

Sorry i haven't got the time to check it out. i will try to do it on the weekend and will report my results :)