每当我们使用 dotnet 格式运行 git commit 时如何格式化代码?

问题描述

我的 pre-commit 文件夹中有一个 hooks 文件,如下所示。这是该文件内容。我们尝试使用每次运行 .editorconfig 时拥有的 git commit 文件来格式化 dotnet 项目。

#!/bin/bash

export tool="dotnet.exe"
echo $OSTYPE
case "$OSTYPE" in
  solaris*) export tool="dotnet" ;;
  darwin*)  export tool="dotnet" ;;
  linux*)   export tool="dotnet" ;;
  bsd*)     export tool="dotnet" ;;
  #msys*)    echo "WINDOWS" ;;
  *)        echo "unkNown: $OSTYPE" ;;
esac

$tool tool install dotnet-format -g || dotnet.exe tool install dotnet-format -g || true
$tool format --check
status=$?
echo $status
# "dotnet format --check" returns 0 for no changes,1 for changes,127 for command not found
if test $status -lt 2
then
    echo "Executed with $tool"
else
    echo "Falling back to .exe"
    dotnet.exe format --check
    status=$?
fi
echo $status
exit $status%

每当我们运行 git commit 时,我都会出于某种原因收到以下错误

➜  HelloWorld git:(dummy) ✗ git commit -m "minor change"
darwin20
Tool 'dotnet-format' is already installed.
.git/hooks/pre-commit: line 14: dotnet.exe: command not found

上面的文件有什么问题吗?我们正在使用 dotnet5。我无法弄清楚这里出了什么问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)