我在.git/hooks/pre-commit文件中有以下内容。
这将在同一目录中成功执行
#!/bin/sh
exec c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -Command " Get-Location | % { '$_\pre-commit-hook.ps1'} | % { & $_ }"
exit
这将在同一目录中成功执行
pre-commit-hook.ps1文件中的代码,但不会捕获退出代码。根据tldp.org ,仅指定退出时将返回上一个退出代码。如果退出代码为非零,则Git钩子将失败,但即使我的powershell脚本返回状态代码1,它也总是成功的。我该怎么做才能捕获来自powershell脚本的退出代码,以使钩子正确运行?
[environment]::Exit(1)
,以返回非零代码给调用者。如果这行得通,我会将其作为我的答案 :-) - Andy Arismendiexit 1
,但那也没用。 - Matt Phillipsexec c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy RemoteSigned -Command "[environment]::Exit(1)"
,它是否有效? - Andy Arismendi