当我们使用dotnet格式运行git commit时,如何格式化代码?
在我的当我们使用dotnet格式运行git commit时,如何格式化代码?,git,asp.net-core,pre-commit,dotnet-format,Git,Asp.net Core,Pre Commit,Dotnet Format,在我的hooks文件夹中有一个pre-commit文件,如下所示。这是该文件的内容。无论何时运行git commit,我们都会尝试使用.editorconfig文件格式化dotnet项目 #!/bin/bash export tool="dotnet.exe" echo $OSTYPE case "$OSTYPE" in solaris*) export tool="dotnet" ;; darwin*) export to
hooks
文件夹中有一个pre-commit
文件,如下所示。这是该文件的内容。无论何时运行git commit
,我们都会尝试使用.editorconfig
文件格式化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%
无论何时运行gitcommit
,出于某种原因,我都会看到下面的错误
➜ 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
。我不知道这里出了什么问题。看第14行:$tool tool install dotnet format-g | | dotnet.exe tool install dotnet format-g | | true
。现在,$tool
设置为什么?$tool tool install dotnet format-g是做什么的,它的退出状态是什么?给定非零退出状态,|
子句将尝试运行什么?仅仅因为存在${tool}
就存在${tool}
吗?