Skip to content

fix(husky): pre-commit hook not working for new projects#71

Merged
asdolo merged 1 commit intomasterfrom
fix/husky_pre_commit_hook_not_working_for_new_projects
Sep 12, 2024
Merged

fix(husky): pre-commit hook not working for new projects#71
asdolo merged 1 commit intomasterfrom
fix/husky_pre_commit_hook_not_working_for_new_projects

Conversation

@asdolo
Copy link
Copy Markdown
Collaborator

@asdolo asdolo commented Sep 11, 2024

What does this do?

  1. This PR fixes the pre-commit hook to work with new repositories, i.e. when a new project is created from the CLI and a developer tries to create an initial commit. The issue was being caused by the command that is responsible of retrieving the current branch name. Replacing it with git branch --show-current solved the issue.
  2. This PR also addresses a warning from husky v9, removing deprecated code.

Why did you do this?

  1. git rev-parse --abbrev-ref HEAD doesn't work for new repositories:
$ mkdir new-project

$ cd new-project

$ git init .
Initialized empty Git repository in /Users/asdolo/dev/new-project/.git/

$ git rev-parse --abbrev-ref HEAD
HEAD
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

However git branch --show-current does work:

$ mkdir new-project

$ cd new-project

$ git init .
Initialized empty Git repository in /Users/asdolo/dev/new-project/.git/

$ git branch --show-current
main
  1. Because now every time pre-commit and commit-msg hooks are executed, they show the following warning message:
husky - DEPRECATED

Please remove the following two lines from .husky/pre-commit:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

They WILL FAIL in v10.0.0

Who/what does this impact?

New and current users of the template.

How did you test this?

  1. Locally running the CLI to create a new project. Then trying to do an initial commit successfully.
  2. Verifying that the warning doesn't show up anymore.

@asdolo asdolo self-assigned this Sep 11, 2024
@asdolo asdolo requested a review from a team as a code owner September 11, 2024 12:03
@github-actions
Copy link
Copy Markdown

💯 Test Coverage

Lines Statements Branches Functions
Coverage: 51%
50.6% (253/500) 46.63% (104/223) 36.12% (69/191)

😎 Tests Results

Tests Skipped Failures Errors Time
68 0 💤 0 ❌ 0 🔥 27.311s ⏱️
👀 Tests Details • (51%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files50.646.6336.1251.57 
report-only-changed-files is enabled. No files were changed in this commit :)

@asdolo asdolo enabled auto-merge September 11, 2024 16:56
@asdolo asdolo merged commit 41a9c6e into master Sep 12, 2024
@asdolo asdolo deleted the fix/husky_pre_commit_hook_not_working_for_new_projects branch September 12, 2024 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants