question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

husky install fails when project is a submodule

See original GitHub issue

Version

0.5.4

Details

when running dotnet husky install from the root of my project directory, or as part of automated installation, I get an error message

.git can't be found (see https://alirezanet.github.io/Husky.Net/guide/getting-started)
Git hooks installation failed

Steps to reproduce

  1. create a new git repository
mkdir new_repo
cd new_repo
git init
  1. add existing project with husky as a sub-module
git submodule add git@github.com:alirezanet/Husky.Net.git
  1. build the submodule to trigger husky installation
cd Husky.Net
dotnet build

you will get the following error

MSBuild version 17.5.0+6f08c67f3 for .NET
  Determining projects to restore...
  .git can't be found (see https://alirezanet.github.io/Husky.Net/guide/getting-started)
  Git hooks installation failed
D:\source\repos\new_repo\Husky.Net\src\Husky\Husky.csproj(61,5): error MSB3073: The command "dotnet husky install" exit
ed with code 1.

Build FAILED.

D:\source\repos\new_repo\Husky.Net\src\Husky\Husky.csproj(61,5): error MSB3073: The command "dotnet husky install" exit
ed with code 1.
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:03.52

Issue Analytics

  • State:open
  • Created 6 months ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
alirezanetcommented, Aug 14, 2023

Option 3: Same as Option 2 but we also install the hooks in the super project .git (I don’t personally see any valid uses for this you only want your submodule hooks to run when doing things on the submodule itself and Option 2 handles that.

I agree, I think user can install husky for super project (if needed) later … so Option 2 makes more sense.

i also added a IgnoreWhenSubmodule option to install … Maybe make the option name a little bit simpler like IgnoreSubmodule … (in the description we can add more details)

Thank you for the effort and I know it is harder than we thought … especially testing different scenarios takes time.

0reactions
Tychuscommented, Aug 13, 2023

This turns out to be a lot more complicated than i anticipated. Our use case is pretty simple, but to handle god knows how many possible setups out there…

Example tree

.
├── .git
├── .gitmodules
├── .husky
│   ├── _
│   │   ├── .gitignore
│   │   └── husky.sh
│   └── task-runner.json
├── Submodule
│   ├── .git (this is a file pointing at `../.git/modules/Submodule` which is your usual .git folder)
│   ├── .husky
│   │   ├── _
│   │   │   ├── .gitignore
│   │   │   └── husky.sh
│   │   └── task-runner.json
│   ├── Submodule.sln
│   └── src
└── TestHuskySubmodules
    ├── TestHuskySubmodules
    └── TestHuskySubmodules.sln

Option 1: If we’re dealing with a submodule we just exit without doing anything. Options 2: If we’re in a submodule we install the hooks from the submodule in the submodule’s .git folder (which is pointed at by the .git file (submodules have there .git dir in the super project .git folder under the modules subfolder) Option 3: Same as Option 2 but we also install the hooks in the super project .git (I don’t personally see any valid uses for this you only want your submodule hooks to run when doing things on the submodule itself and Option 2 handles that.

Let me know what you think. Should Option 3 be handled ?

PS: i also added a IgnoreWhenSubmodule option to install when set we go with Option 1. This means i will also have to change the attach command so it adds that option when specified. any input on what the best way to do that is welcome

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure husky (git hooks) in submodules · Issue #192
This script helps you add the hooks in the main repository and a submodule public : "postinstall": "husky install && cd public &&...
Read more >
React Setup: Git submodule is ignored by Husky - 6.0.0
Inside this project, I have another project named a-b-c which is a git submodule . I am using Husky: v6.0.0 and have set...
Read more >
Error when building a react app that has husky installed
The build works if I run it after clearing the cache, but not normally. Any commit I push will trigger a build and...
Read more >
How to Fix the “Fatal: Not a Git Repository” Error
In this tutorial, learn some of the reasons why the “fatal: not a git repository” error shows up—and how to fix it.
Read more >
Solving “Fatal: Not A Git Repository” (Or Any Of The Parent ...
The error 'fatal: not a git repository' occurs when you try to run a Git command but are not inside a Git repository....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found