Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre commit/push hooks fail in the latest version #123

Open
svsool opened this issue May 1, 2022 · 13 comments · May be fixed by #137
Open

Pre commit/push hooks fail in the latest version #123

svsool opened this issue May 1, 2022 · 13 comments · May be fixed by #137

Comments

@svsool
Copy link

svsool commented May 1, 2022

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
@stefanluptak
Copy link

Same here.

@murilobauerc
Copy link

murilobauerc commented Jun 23, 2022

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.

@stocks29
Copy link

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

@TheFirstAvenger
Copy link

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.

@qgadrian
Copy link
Owner

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 🙏

@djthread
Copy link

djthread commented Nov 13, 2022

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 !

@qgadrian
Copy link
Owner

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 qgadrian linked a pull request Nov 18, 2022 that will close this issue
@qgadrian
Copy link
Owner

qgadrian commented Nov 18, 2022

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.

@djthread
Copy link

djthread commented Nov 18, 2022

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.

@apoorv-2204
Copy link

Screenshot_20221123_141150

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

@qgadrian
Copy link
Owner

qgadrian commented Dec 5, 2022

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?

@ahamez
Copy link

ahamez commented Dec 27, 2022

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

@fbettag
Copy link

fbettag commented Feb 23, 2023

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

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 a pull request may close this issue.

10 participants