Nea*_*ers 6 git powershell-4.0
如何解释来自调用"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
Run Code Online (Sandbox Code Playgroud)
输出:
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.
Run Code Online (Sandbox Code Playgroud)
我想要使用此代码的任何更大的脚本,我包括:
$ErrorActionPreference = "Stop" #Special Poweshell Syntax to Stop on First Error
Run Code Online (Sandbox Code Playgroud)
这样它就会在第一个错误时停止.
即使我在一个非空的项目上运行它,我看到红色和类似于上面的错误(在此次运行中使用--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
Run Code Online (Sandbox Code Playgroud)
如果我从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.
Run Code Online (Sandbox Code Playgroud)
正如我在“ PowerShell Capture Git Output ”中提到的,由于 Git 命令可以在 stderr (而不是 stdout)上输出信息消息,请尝试(使用 Gti 2.16+)
set GIT_REDIRECT_STDERR=2>&1
Run Code Online (Sandbox Code Playgroud)
(或将该变量设置适应您的脚本)
这可能会避免您的脚本在第一个“错误”时停止,这实际上不是错误
我最终使用了
Invoke-Git“ Git clone: Redirect stderr to stdout but keep errors being write to stderr ”中的包装函数
| 归档时间: |
|
| 查看次数: |
1141 次 |
| 最近记录: |