elixir_git_hooks icon indicating copy to clipboard operation
elixir_git_hooks copied to clipboard

Don't set any project path by default

Open qgadrian opened this issue 2 years ago β€’ 6 comments

This PR removes the auto directory change on the project. To change the path where to execute the hooks, a project_path config will need to be set.

The changes here can potentially break a current setup for a project that is relying on the auto cd.

Fixes #123 #133

qgadrian avatar Nov 18 '22 03:11 qgadrian

Thanks for looking at this, AdriΓ‘n! I just gave this another try and noticed the same thing as I mentioned on #123. Checking out my project freshly and setting the git_hooks dep in mix.exs with 'github' and 'branch' set to this PR, 'mix compile' shows the installing message, but at the end, my pre-push file is not created under .git/hooks.

β†— Installing git hooks...

I even looked at your diff here and tried swapping back the line in lib/mix/tasks/git_hooks/install.ex which seemed to be the only relevant change... Same result every time I rm -rf _build/dev/lib/git_hooks and mix compile: no hook file generated!

However, if I then switch back to 0.7.3 and do mix deps.get, mix compile, of course the installing message appears here, too... but the git hook file is created as expected, consistently!

I can't seem to even theorize what would make the difference! ...

djthread avatar Nov 20 '22 23:11 djthread

Thanks for looking at this, AdriΓ‘n! I just gave this another try and noticed the same thing as I mentioned on #123. Checking out my project freshly and setting the git_hooks dep in mix.exs with 'github' and 'branch' set to this PR, 'mix compile' shows the installing message, but at the end, my pre-push file is not created under .git/hooks.

β†— Installing git hooks...

I even looked at your diff here and tried swapping back the line in lib/mix/tasks/git_hooks/install.ex which seemed to be the only relevant change... Same result every time I rm -rf _build/dev/lib/git_hooks and mix compile: no hook file generated!

However, if I then switch back to 0.7.3 and do mix deps.get, mix compile, of course the installing message appears here, too... but the git hook file is created as expected, consistently!

I can't seem to even theorize what would make the difference! ...

That is weird, @djthread can you please add the config :git_hooks, verbose: true config and try again? What is the path used to install the hooks?

I've just tried on a fresh install and it worked fine. Just to be clear, the hooks install will only occur when the dep is compiled or when you execute mix git_hooks.install, but that doesn't seem to be your case :/

qgadrian avatar Dec 05 '22 22:12 qgadrian

Hi @qgadrian

Thanks for working on this fix. I've pulled this PR and the auto installation is working as expected when specifying the project's root πŸ‘

config :git_hooks, auto_install: true, verbose: true, project_path: File.cwd!()

Would really appreciate if included in the next version release, cheers!

MajdSehwail avatar Feb 26 '23 16:02 MajdSehwail

Hi @qgadrian

Thanks for working on this fix. I've pulled this PR and the auto installation is working as expected when specifying the project's root πŸ‘

config :git_hooks, auto_install: true, verbose: true, project_path: File.cwd!()

Would really appreciate if included in the next version release, cheers!

Thanks for the feedback. Do you need to explicitly specify the :project_path field?

IMO this dependency should work out of the box with _default project architecture, and use that option only for edge cases. That means, without setting :project_path it should work on any mix new project.

qgadrian avatar Feb 28 '23 18:02 qgadrian

IMO this dependency should work out of the box with _default project architecture, and use that option only for edge cases. That means, without setting :project_path it should work on any mix new project.

Yes we had to specifically set it. Perhaps it's due to having multiple config files (git_hooks config only exists in dev.exs)?

.
β”œβ”€β”€ mix.exs
β”œβ”€β”€ mix.lock
β”œβ”€β”€ config
   β”œβ”€β”€config.exs
   β”œβ”€β”€dev.exs
   β”œβ”€β”€prod.exs
   β”œβ”€β”€releases.exs
   β”œβ”€β”€test.exs
β”œβ”€β”€ apps
β”œβ”€β”€ deploy
β”œβ”€β”€ rel
β”œβ”€β”€ .github
β”œβ”€β”€ .credo.exs
β”œβ”€β”€ .formatter.exs
β”œβ”€β”€ .tools-versions
β”œβ”€β”€ LICENSE
└── README.md

MajdSehwail avatar Mar 01 '23 14:03 MajdSehwail

Hi @qgadrian,

the problem seems to be here:

  def resolve_app_path do
    repo_path =
      resolve_git_path_based_on_git_version()
      |> Path.dirname()

    Path.relative_to(File.cwd!(), repo_path)
  end

During auto install, File.cwd!() returns /<project>/deps/git_hooks and repo_path returns ../../.git/.

I couldn't figure out what's the purpose of Path.relative_to(File.cwd!(), repo_path) here.

When running mix git_hooks.install, File.cwd!() returns /<project> and repo_path returns .git/, so the repo_path is not doing anything.

Can you double check this and provide some details please.

Thanks

sergiolc avatar Oct 25 '23 11:10 sergiolc