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

mono-repo with multiple applications #114

Closed
jgallinari opened this issue Feb 18, 2022 · 5 comments
Closed

mono-repo with multiple applications #114

jgallinari opened this issue Feb 18, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@jgallinari
Copy link

Hello,

I'm using a mono-repo with multiple applications in their sub-directory, like

repo
└─ .git
└─ app1
   └─ .git
└─ app2
   └─ .git

So far, I had installed git_hooks v0.6.5 in the app sub-directories for some pre_commit hook defined for ex. in repo/app1/config/config.exs like

if Mix.env() != :prod do
  config :git_hooks,
    auto_install: true,
    verbose: true,
    hooks: [
      pre_commit: [
        tasks: [
          {:cmd, "mix credo"},
...

but it never worked for me: hooks never got fired automatically.
Then I saw #96.
So I removed repo/app1/.git/hooks/ and I updated to git_hooks v0.7.1
Before that, I had only .samples in repo/.git/hooks/.
After the update, a new pre-commit file appeared in repo/.git/hooks that showed

#!/bin/sh
[ "/Users/jerome/repo/app1/deps/git_hooks" != "" ] && cd /Users/jerome/repo/app1/deps/git_hooks

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

So, it seems to me that it shouldn't work if I would do it also in app2/, doesn't it?

Then I tried anyway to commit a file in app1/ with some credo issue I introduced, which produced

repo> cd app1
app1> git commit -m 'test pre-commit hook' lib/app1/worker.ex
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

So maybe I did something wrong, but I can't get it to work in my case.
If, just for testing, I change pre-commit to be

#!/bin/sh
#[ "/Users/jerome/repo/app1/deps/git_hooks" != "" ] && cd /Users/jerome/repo/app1/deps/git_hooks
cd /Users/jerome/repo/app1
...

Then the same test would work

repo> cd app1
app1> git commit -m 'test pre-commit hook' lib/app1/worker.ex
↗ Running hooks for :pre_commit
...
× `pre_commit`: `mix credo` execution failed

Any thought about that? 🙂

@qgadrian qgadrian added the bug Something isn't working label Feb 20, 2022
@qgadrian
Copy link
Owner

Hello @jgallinari! Thanks for reporting the issue!

I believe this is the same issue as #113 correct? If that is the case, I opened a PR to validate adding a config to set up the project would work #120

In that case, if this library it's available on both of your projects it should work for both of them.

@jgallinari
Copy link
Author

Hello,
Not sure to understand how it's supposed to work 😞
In repo/app1/config/config.exs, I put:

if Mix.env() != :prod do
  config :git_hooks,
    project_path: "./app1",
    auto_install: true,
    verbose: true,
    hooks: [
      pre_commit: [
        tasks: [
          {:cmd, "mix credo"},

And then, by installing, I got

repo/app1> mix git_hooks.install
↗ Installing git hooks...
↗ Writing git hook for `pre_commit` to `../.git/hooks/pre-commit`
↗ Backing up git hook file `../.git/hooks/pre-commit` to `../.git/hooks/pre-commit.pre_git_hooks_backup`
↗ Writing git hook for `pre_push` to `../.git/hooks/pre-push`
↗ Backing up git hook file `../.git/hooks/pre-push` to `../.git/hooks/pre-push.pre_git_hooks_backup`

and repo/.git/hooks/pre-commit now contains:

#!/bin/sh

[ "./app1" != "" ] && cd "./app1"

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

which works.
But what am I supposed to do with repo/app2 then?
I don't see how repo/app1 and repo/app2 can co-exist with a common config in repo/.git/hooks/pre-commit, can't they?

@qgadrian
Copy link
Owner

qgadrian commented Apr 1, 2022

Hello, Not sure to understand how it's supposed to work 😞 In repo/app1/config/config.exs, I put:

if Mix.env() != :prod do
  config :git_hooks,
    project_path: "./app1",
    auto_install: true,
    verbose: true,
    hooks: [
      pre_commit: [
        tasks: [
          {:cmd, "mix credo"},

And then, by installing, I got

repo/app1> mix git_hooks.install
↗ Installing git hooks...
↗ Writing git hook for `pre_commit` to `../.git/hooks/pre-commit`
↗ Backing up git hook file `../.git/hooks/pre-commit` to `../.git/hooks/pre-commit.pre_git_hooks_backup`
↗ Writing git hook for `pre_push` to `../.git/hooks/pre-push`
↗ Backing up git hook file `../.git/hooks/pre-push` to `../.git/hooks/pre-push.pre_git_hooks_backup`

and repo/.git/hooks/pre-commit now contains:

#!/bin/sh

[ "./app1" != "" ] && cd "./app1"

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

which works. But what am I supposed to do with repo/app2 then? I don't see how repo/app1 and repo/app2 can co-exist with a common config in repo/.git/hooks/pre-commit, can't they?

If it's an umbrella application, if both applications use this library you can have this library configured at the root config file instead of on each application.

If it's not an umbrella application I can try to dig more to support your case ☺️. It would be very helpful to speed up things if you can provide an example project to reproduce the issue.

@jgallinari
Copy link
Author

Sorry for the delay of my response.
I could not get it to work until I re-installed the git_hooks manually with mix git_hooks.install, and suddenly it started to work as expected 😮 : .git/hooks/pre-commit got the right cd command.
Thanks for your help!
I think you can close the ticket.

@qgadrian
Copy link
Owner

@jgallinari glad to hear. If you have any issues please free to ping me here or open a new ticket ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants