如何解释这个调用“GitLab”的PowerShell脚本(实际上使用GitLab)产生的错误。我能克隆一个空目录并使它正常工作而不会出现错误吗?
$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 所以它在第一个错误时停止。
即使在一个非空项目上运行它,我也会看到类似于上面的红色和错误(从这个运行中删除了--本地和-详细的):
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.发布于 2019-02-11 05:45:49
正如我在"PowerShell Capture Git Output“中提到的,由于Git命令可以在stderr (instead of stdout)上输出信息消息,所以尝试(使用Gti 2.16+)
set GIT_REDIRECT_STDERR=2>&1(或根据脚本调整变量设置)
这可能会避免脚本在第一个“错误”时停止,这实际上不是一个错误。
OP NealWalters添加in the comments
最后,我使用了来自“
Invoke-Git”的包装函数Git clone: Redirect stderr to stdout but keep errors being written to stderr。
https://stackoverflow.com/questions/54372601
复制相似问题