elixir_git_hooks icon indicating copy to clipboard operation
elixir_git_hooks copied to clipboard

Pre commit/push hooks fail in the latest version

Open svsool opened this issue 2 years ago • 13 comments

Hi 👋 ,

Thanks for this project!

Pre-commit or push hooks fail in the latest version for me under macOS Monterey 12.3 (whether it matters), I wonder if conditional cd shown in the screenshot is the culprit. (this commit)

image

image

My config:

if Mix.env() == :dev do
  config :git_hooks,
    verbose: true,
    hooks: [
      pre_commit: [
        tasks: [
          {:cmd, "mix format --check-formatted"}
        ]
      ],
      pre_push: [
        tasks: [
          {:cmd, "mix quality"}
        ]
      ]
    ]
end

Seem to work fine with the version 0.6.5.

How to reproduce:

  1. Download git_hooks_bug.zip
  2. mix deps.get && mix compile
  3. touch test.txt && git commit -m whatever

svsool avatar May 01 '22 08:05 svsool

Same here.

stefanluptak avatar May 30 '22 14:05 stefanluptak

Same issue happened here. Tried to execute:

➜ mix deps.get && mix deps.compile
➜ git commit -m "test"

Results:

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

As an alternative 0.6.5 is working fine.

murilobauerc avatar Jun 23 '22 14:06 murilobauerc

Unfortunately :mix_task doesn't respect result values in 0.6.5, so if you downgrade be sure to use :cmd.

stocks29 avatar Sep 14 '22 20:09 stocks29

We ran into this, and the current fix we have is to run mix git_hooks.install whenever we get this missing dependencies error even after running deps.get.

TheFirstAvenger avatar Sep 21 '22 15:09 TheFirstAvenger

I have limited time but actively looking at this when I have time to focus on it 😞

So far, I cannot reproduce this in a reliable way. The example project provided by this issue gets fixed after running mix git_hooks.install, but this should never happen in the first case so something it's definitely not right.

I will keep investigating, but it will be great if I can get more details such as the folder structure of the repo as I think it's the root of the issue 🙏

qgadrian avatar Sep 21 '22 17:09 qgadrian

When the auto_install feature creates .git/hooks/pre-push it looks like this:

#!/bin/sh

[ "/Users/myuser/code/myapp/deps/git_hooks" != "" ] && cd "/Users/myuser/code/myapp/deps/
git_hooks"

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

I notice that if I remove the first line there, the git hook seems to work properly!

It seems to mean that mix deps.get is ran in the deps/git_hooks dir and not in the project root as we may want instead.

What is the idea with that cd line? Thanks, @qgadrian !

djthread avatar Nov 13 '22 01:11 djthread

When the auto_install feature creates .git/hooks/pre-push it looks like this:

#!/bin/sh

[ "/Users/myuser/code/myapp/deps/git_hooks" != "" ] && cd "/Users/myuser/code/myapp/deps/
git_hooks"

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

I notice that if I remove the first line there, the git hook seems to work properly!

It seems to mean that mix deps.get is ran in the deps/git_hooks dir and not in the project root as we may want instead.

What is the idea with that cd line? Thanks, @qgadrian !

Hey @djthread

I am currently reviewing this issue, expect a preview version by this week 🤞

Regarding the cd... things started going south with this commit trying to provide more flexibility on some custom project setups (elixir projects not in the root of the git repo, submodules...) :/

qgadrian avatar Nov 15 '22 00:11 qgadrian

I created a PR and will remove the auto directory change of this library, it's giving more problems than solving anything.

Can anyone please test 0.8.0-pre0 version and confirm the issues are gone? I've tested it on my projects and they work fine, I'm having a hard time trying to reproduce this every time.

qgadrian avatar Nov 18 '22 03:11 qgadrian

Hm. I checked out my app fresh and changed my git_hooks dependency to the fix-hooks-and-dependencies branch.

During compilation, I saw

↗ Installing git hooks...

And the dev phoenix app started up ...

My pre-push hook which should have been created wasn't created at all.

I'm not certain of many details, so feel free to ask questions.

djthread avatar Nov 18 '22 16:11 djthread

Screenshot_20221123_141150

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

apoorv-2204 avatar Nov 23 '22 08:11 apoorv-2204

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

@apoorv-2204 is this happening with 0.7.3 or 0.8.0-pre0 version?

qgadrian avatar Dec 05 '22 22:12 qgadrian

FWIW, I get the same error with 0.8.0-pre0:

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

ahamez avatar Dec 27 '22 22:12 ahamez

We ran into this, and the current fix we have is to run mix git_hooks.install whenever we get this missing dependencies error even after running deps.get.

this works for me:

mix deps.compile && mix git_hooks.install

fbettag avatar Feb 23 '23 13:02 fbettag