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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't install husky in 'postinstall' if '.git' directory doesn't exists #98

Closed
wants to merge 1 commit into from

Conversation

mondeja
Copy link
Member

@mondeja mondeja commented Feb 6, 2021

I know that this is an edge case, but I found it interesting. If you download the repository using Github UI (Code -> Download ZIP), extract the repository and executes npm install, next error is raised during the installation:

postinstall error
> simple-icons-font@4.9.0 postinstall /.../simple-icons-font-develop
> is-ci || husky install

/.../simple-icons-font-develop/node_modules/husky/lib/commands/install.js:20
        throw new Error(".git can't be found");
        ^

Error: .git can't be found
    at Object.install (/.../simple-icons-font-develop/node_modules/husky/lib/commands/install.js:20:15)
    at Object.<anonymous> (/.../simple-icons-font-develop/node_modules/husky/lib/bin.js:43:19)

Which means that husky needs the .git directory to exist or will fail. I'm sure that no one would do this, only me on Windows 馃槄, but anyways seems to me that this should be possible because someone could install this only for test it quickly, even if are not planning doing commits.

The proposed change seems counterintuitive but is the most straightforward way of do this: if .git directory does not exists, exits with 0 code and don't executes husky install, otherwise the node -e command fails and husky install is executed.

@mondeja mondeja added the meta Issues or pull requests regarding the project or repository itself label Feb 6, 2021
@mondeja mondeja changed the title Do not install husky in 'postinstall' if '.git' directory doesn't exists Don't install husky in 'postinstall' if '.git' directory doesn't exists Feb 6, 2021
@ericcornelissen
Copy link
Contributor

Interesting 馃ぃ

This really seems more like an upstream issue to me though 馃 did you investigate if there is any discussion in this regard in the Husky repository? Alternatively, are there no scripts like is-ci to check if the .git repo exists?

This just seems like a very hacky solution for a very niche "problem" (not even really a problem, the dependencies are still installed), and the fact that it is counter-intuitive doesn't add to the appeal 馃槄

I get that that is arguably also true for the is-ci check, but it is actually almost never a problem if you install git hooks in CI, one may just want to disable it because it is pointless

@mondeja
Copy link
Member Author

mondeja commented Feb 7, 2021

did you investigate if there is any discussion in this regard in the Husky repository? Alternatively, are there no scripts like is-ci to check if the .git repo exists?

I've done all this before:

  • Nobody has asked never this in husky repository, maybe this form of installation is too weird.
  • I haven't found any script to check if .git directory exists. I suppose that the check is too simple that nobody has needed.

This just seems like a very hacky solution for a very niche "problem" (not even really a problem, the dependencies are still installed), and the fact that it is counter-intuitive doesn't add to the appeal 馃槄

I agree, feel free to close this 馃憤 I will probably open an issue in husky repository to check what their devs have to say about this...

@ericcornelissen
Copy link
Contributor

We can leave this open until we get more details from upstream 馃檪

@mondeja
Copy link
Member Author

mondeja commented Feb 8, 2021

Linking typicode/husky#851

@mondeja
Copy link
Member Author

mondeja commented Feb 8, 2021

Has been fixed in typicode/husky@f8f1afe, so there is no need to do anything here. After 5.0.9 husky will print a message if .git directory is not found instead of raising an error.

@mondeja mondeja closed this Feb 8, 2021
@ericcornelissen
Copy link
Contributor

Awesome 馃憤

@danielrsantana-sastrix
Copy link

danielrsantana-sastrix commented Mar 1, 2021

In my case the problem was happening in in the version 5.1.2 due to a wrong configuration in my package.json:

  scripts: {
     (...),
      "postinstall": "husky install"
  },

This command is automatically added by husky init.

After removing this command, the error disappeared.

   /Users/daniels/projects/sastrix/sastrix-app/server/node_modules/husky/lib/commands/install.js:20
   throw new Error(".git can't be found");

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta Issues or pull requests regarding the project or repository itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants