哈士奇:无法生成 .husky/commit-msg:没有此文件或目录

huangapple go评论65阅读模式
英文:

Husky: cannot spawn .husky/commit-msg: No such file or directory

问题

我已经与哈士奇合作了几年了。我们开始了一个新项目,并确保在预提交和提交消息验证中添加了哈士奇。但这次在Windows机器上出现了一些问题。

我们在项目中使用Mac配置了哈士奇。当我们添加了一个使用Windows机器的新开发人员时,提交时出现了错误。

我们有以下内容:

  • 预提交 (pre-commit)
  • 提交消息验证 (commit-msg)

.husky/pre-commit

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

npx lint-staged

.husky/commit-msg

#!/bin/sh
echo $(dirname "$0")
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1

.husky/_/husky.sh

#!/usr/bin/env sh
if [ -z "$husky_skip_init" ]; then
  debug () {
    if [ "$HUSKY_DEBUG" = "1" ]; then
      echo "husky (debug) - $1"
    fi
  }

  readonly hook_name="$(basename -- "$0")"
  debug "starting $hook_name..."

  if [ "$HUSKY" = "0" ]; then
    debug "HUSKY env variable is set to 0, skipping hook"
    exit 0
  fi

  if [ -f ~/.huskyrc ]; then
    debug "sourcing ~/.huskyrc"
    . ~/.huskyrc
  fi

  readonly husky_skip_init=1
  export husky_skip_init
  sh -e "$0" "$@"
  exitCode="$?"

  if [ $exitCode != 0 ]; then
    echo "husky - $hook_name hook exited with code $exitCode (error)"
  fi

  if [ $exitCode = 127 ]; then
    echo "husky - command not found in PATH=$PATH"
  fi

  exit $exitCode
fi

.husky 文件夹中的文件。
预提交文件没有任何问题,可以正常工作。但是在提交消息验证时出现以下错误:

error: cannot spawn .husky/commit-msg: No such file or directory

甚至没有被调用。

是否有人遇到过这个问题?有没有解决方法?

注意:请不要建议使用 --no-verify,因为它与我们尝试实现的相反。

英文:

I have been working with husky for few years now. We started a new project and was sure to add husky for pre-commit and commit-msg linting. But this time we faced some issue in the windows machine.

We configured the husky in the project using a mac. When we added new dev who has a windows machine, there was error in commiting.

we have,

  • pre-commit
  • commit-msg

.husky/pre-commit

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

npx lint-staged

.husky/commit-msg

#!/bin/sh
echo $(dirname "$0")
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1

.husky/_/husky.sh

#!/usr/bin/env sh
if [ -z "$husky_skip_init" ]; then
  debug () {
    if [ "$HUSKY_DEBUG" = "1" ]; then
      echo "husky (debug) - $1"
    fi
  }

  readonly hook_name="$(basename -- "$0")"
  debug "starting $hook_name..."

  if [ "$HUSKY" = "0" ]; then
    debug "HUSKY env variable is set to 0, skipping hook"
    exit 0
  fi

  if [ -f ~/.huskyrc ]; then
    debug "sourcing ~/.huskyrc"
    . ~/.huskyrc
  fi

  readonly husky_skip_init=1
  export husky_skip_init
  sh -e "$0" "$@"
  exitCode="$?"

  if [ $exitCode != 0 ]; then
    echo "husky - $hook_name hook exited with code $exitCode (error)"
  fi

  if [ $exitCode = 127 ]; then
    echo "husky - command not found in PATH=$PATH"
  fi

  exit $exitCode
fi

files inside the .husky folder.
the pre-commit file works just fine without any issue.
but we get following error in case of commit-msg

error: cannot spawn .husky/commit-msg: No such file or directory

it is not even getting invoked.

does anyone encountered this issue ? Is there any fix for this?

NB : Please don't suggest --no-verify as it does the opposite of what we are trying to implement.

答案1

得分: 1

解决方案:

.husky/commit-msg中删除开头的空行。

英文:

I lost two day trying to fix this issue. The solution is very simple.

Solution :

Removed the empty line at the beginning in .husky/commit-msg.

huangapple
  • 本文由 发表于 2023年5月29日 15:39:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355479.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定