首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行Powershell中的"Git-Clone“,即使它看起来工作正常,也会产生错误。

运行Powershell中的"Git-Clone“,即使它看起来工作正常,也会产生错误。
EN

Stack Overflow用户
提问于 2019-01-25 20:52:22
回答 1查看 11K关注 0票数 19

如何解释这个调用“GitLab”的PowerShell脚本(实际上使用GitLab)产生的错误。我能克隆一个空目录并使它正常工作而不会出现错误吗?

代码语言:javascript
复制
$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

输出:

代码语言:javascript
复制
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.

在我想要使用此代码的较大脚本中,我包括以下内容:

代码语言:javascript
复制
$ErrorActionPreference = "Stop"  #Special Poweshell Syntax to Stop on First Error 

所以它在第一个错误时停止。

即使在一个非空项目上运行它,我也会看到类似于上面的红色和错误(从这个运行中删除了--本地和-详细的):

代码语言:javascript
复制
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命令提示符运行,它可以很好地运行一些状态:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-11 05:45:49

正如我在"PowerShell Capture Git Output“中提到的,由于Git命令可以在stderr (instead of stdout)上输出信息消息,所以尝试(使用Gti 2.16+)

代码语言:javascript
复制
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

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54372601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档