[英]Running “Git-Clone” from Powershell giving errors even when it seems to work
如何解釋來自調用“Git Clone”(實際使用GitLab)的PowerShell腳本的錯誤。 我可以克隆一個空目錄並使其工作而不會出錯嗎?
$path1 = "d:\GitPath"
$path2 = "${path1}\mycompany-mygroup-nealtestautomation01-map"
$gitLabHttp = "http://git.mycompany.com/MyGroup/nealtestscriptaddedproject.git"
$gitLabHttp = "http://git.mycompany.com/MyGroup/mycompany-gwcustomers-nealtestautomation01-map.git"
rd $path2
cd $path1
git clone $gitLabHttp --local --verbose
輸出:
git : Cloning into 'mycompany-mygroup-nealtestautomation01210-map'...
At D:\Scripts\GitCloneTest.ps1:7 char:1
+ git clone $gitLabHttp --local --verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Cloning into '...mation01-map'...:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
warning: --local is ignored
warning: You appear to have cloned an empty repository.
我想要使用此代碼的任何更大的腳本,我包括:
$ErrorActionPreference = "Stop" #Special Poweshell Syntax to Stop on First Error
這樣它就會在第一個錯誤時停止。
即使我在一個非空的項目上運行它,我看到紅色和類似於上面的錯誤(在此次運行中使用--local和--verbose):
git : Cloning into 'xxx.yyy.CanInvToOutZZZ210.Map'...
At D:\Scripts\GitCloneTest2.ps1:5 char:1
+ git clone $gitLabHttp
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Cloning into 'E...Intl210.Map'...:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
如果我從Windows命令提示符運行,它運行良好的一些統計信息:
D:\GitGWCustomerMaps\Test2>git clone myrealurlhidden
Cloning into 'XXX.YYY.CanInvToOutZZZZ210.Map'...
remote: Counting objects: 29, done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 29 (delta 9), reused 0 (delta 0)
Unpacking objects: 100% (29/29), done.
正如我在“ PowerShell Capture Git Output ”中提到的,由於Git命令可以在stderr( 而不是stdout )上輸出信息消息,請嘗試(使用Gti 2.16+)
set GIT_REDIRECT_STDERR=2>&1
(或將該變量設置調整到您的腳本)
這可能會避免您的腳本停止在第一個“錯誤”,這實際上不是一個錯誤
我最終使用了包裝函數
Invoke-Git
從“ Git clone:Redirect stderr to stdout但是將錯誤寫入stderr ”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.