简体   繁体   中英

.husky/pre-commit: 2: .: Can't open .husky/_/husky.sh

In a project, we use Husky but when I try to add a commit with git add. and git commit -m "test", I receive below error

.husky/pre-commit: 2: .: Can't open.husky/_/husky.sh 在此处输入图像描述

How can i fix this problem?

My operating system is Windows but I use Ubuntu on this project

I have a pre-commit file and it is as below在此处输入图像描述

Also the codes for husky.sh is below

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

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

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

  exit $exitCode
fi

for this problem, I have come up with a solution as below. In my IDE, line endings use CRLF by default. So I changed it to LF from the bottom right corner of the IDE and it worked在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM