我在一个关于bash 的问题上看到了这个构造
git -C 'repo-path' pull || git clone https://server/repo-name 'repo-path'
因此,如果git pull
失败,那么执行git clone
,这似乎是一种非常干净的方法。
PowerShell中的等效语法是什么?
我相信语法在PowerShell核心上会像预期的那样工作,因为它现在支持||和&;。
如果您需要在PowerShell之前的核心系统上执行此操作,可以使用$lastExitCode
来确定前一步是否有效。
git -C 'repo-path' pull
# If the previous line worked, lastExitCode will be zero
if ($lastexitCode) {
git clone https://server/repo-name 'repo-path'
}