git 和来自 Powershell 的 psake

git and psake from Powershell

我正在尝试通过 Powershell 中的 psake 使用 git.exe 从 bitbucket 中自动提取我们代码的最新版本,但我遇到了一些问题。

我在任务中有以下代码:

    Exec {
       &('c:\Program Files\Git\bin\git.exe') pull --progress --no-rebase -v origin
    }

但我收到以下错误:

Error: 25/04/2016 22:51:02:
At C:\work\mycompany\buildapp\psakefile.ps1:117 char:5 +     
&('c:\Program Files\Git\bin\git.exe') pull --progress --no-rebase -v origin
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
[<<==>>] Exception: From bitbucket.org:mybitbucketusername/work

我想那是因为我没有从我的克隆文件夹中调用 git.exe,但我该怎么做呢?有没有办法 a) 从我当前位置调用 git 并将其应用到特定的克隆文件夹?或者 b) 如果 a) 无法完成,我该如何更改 psake 中的文件夹?

假设我可以解决第一个问题,我如何找出从 git 返回的确切错误。刚刚得到异常:来自 bitbucket.org 太模糊了。

有没有更好的方法从 bitbucket 中提取我的代码?我应该使用 Powershell 中的 psake 调用 git bash(对于 windows)吗?那个更好吗?如果是这样,我如何使用特定的命令行调用它。

如果您希望我提供更多信息,请告诉我。

更新一:

这是我调用 git pull

时得到的结果
Error: 26/04/2016 15:46:30: 
At C:\work\mycompany\buildapp\psakefile.ps1:120 char:5 +     
&('c:\Program Files\Git\bin\git.exe') pull +
[<<==>>] Exception: There is no tracking information for the current branch.

这是预料之中的,因为 c:\work\mycompany\buildapp 不是克隆的文件夹。它是克隆文件夹的子文件夹。

我需要能够在 c:\work\mycompany\buildapp 中调用 git(因为这是我的脚本 运行 的来源)但我需要 git 来提取数据来自 c:\work\mycompany\.

我希望以上内容能澄清我的问题。

谢谢。

更新 2:

以下 git 命令行完美运行 运行 从任何文件夹调用的命令行:

git clone git@bitbucket.org:myusername/work.git "c:/Work/"

git --git-dir=c:\work\.git --work-tree=c:\work pull origin master

以下适用于 PSake:

 Exec {
   &('c:\Program Files\Git\bin\git.exe') clone
      git@bitbucket.org:myusername/work.git 'C:/Work/'
 }

但是这样调用时 pull 仍然不起作用:

 exec {
   &('c:\program files\git\bin\git.exe') --git-dir=c:\work\.git 
      --work-tree=c:\work pull origin master
 }

我仍然收到错误消息:

Error: 29/04/2016 10:06:36: 
At C:\temp\buildapp\psakefile.ps1:124 char:8 +        
&('c:\program files\git\bin\git.exe') --git-dir=c:\work\.git - ... +  
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
[<<==>>] Exception: From bitbucket.org:myusername/work

不幸的是,异常并没有告诉我们太多信息。

我已经尝试了 quotes/double 引号与参数的各种组合,但无济于事。

有什么想法吗?

转到 post 我自己的答案,但非常感谢@etanreisner 和 @spijn 的帮助和建议。

在这个问题上浪费了大量时间,而这一切都归结为一件事!! 运行 我的脚本直接在 ISE 中。在我 post 在 psake 上编辑错误报告后,Dave Wyatt 向我强调了这一点。他是这样说的:

Is this happening from the powershell.exe console, from the ISE, or both? The ISE treats any console application that writes to the stderr stream as an exception, but powershell.exe does not. (This is because powershell.exe is a win32 console application, and can just let that subsystem handle interaction with other console apps. The ISE has its own code to pretend to be a console when it's really a WinForms app, and the behavior is different. I believe Microsoft intends to fix this soon.)

Anyhow, git.exe writes to stderr all over the place, which is why I always keep a separate console open when I want to run git commands (so I don't have to stare at the red text all the time.)

这是我在 github 上创建的实际问题:Psake always throws an exception when calling git.exe and trying to clone #174

在 Powershell 而不是 ISE 中尝试以下操作后:

Git 克隆:

Exec {
&('c:\program files\git\bin\git.exe') clone
   git@bitbucket.org:myusername/work.git "C:\Work"
}

Git拉:

exec {
&('c:\program files\git\bin\git.exe') --git-dir="c:/work/.git" 
   --work-tree="c:/work/" pull origin master
}

希望这对其他人有所帮助,并且不会像我一样浪费那么多时间在如此琐碎但不明显的事情上,除非你知道它!