Skip to content

Git hook failed on CI/CD git checkout #109

@darthkurak

Description

@darthkurak

Version

Newest

Details

I have an advanced build system in Nuke for my .NET apps.
That build system makes sure that dotnet husky install is called each time when I build the app.
It works almost perfectly fine.
I have one issue in CI/CD case.
When my Azure DevOps pipeline uses git checkout task, and this is not a first run - I am getting:
.husky/post-checkout: 2: .: Can't open .husky/_/husky.sh error.
I debugged this and the flow is following:

  • When first run on Azure Devops agent - repository is freshly cloned, so, there is not git hooks yet.
  • Then the build system is run, which calls "dotnet husky install" - and adds git hook
  • Build succeed
  • On the next pipeline run on this agent, the git checkout task makes git clean which removes _/husky.sh (because it is not committed) - but git hook already exists. So, git checkout fails due to missing _/husky.sh from .husky/post-checkout.

What is the best recommendation here?
I found a few workarounds, but I am not sure if they are valid and proper:

  • check for the existence of _/husky.sh in post-checkout script
  • run dotnet husky install in post-checkout script
  • commit _/husky.sh and change _/.gitignore from * to cache - this one unfortunately is overridden each time when someone/something run dotnet husky install

Steps to reproduce

I described above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions