C# 需要在cake脚本中的GitPull方法中获得修改文件的详细信息

C# 需要在cake脚本中的GitPull方法中获得修改文件的详细信息,c#,git,libgit2sharp,cakebuild,C#,Git,Libgit2sharp,Cakebuild,您好,我正在使用GitPull方法将更改拉入存储库 参考下面的链接 我需要在执行GitPull方法时获取更新文件的日志 是否有任何方法可以使用下面的页面获取这些详细信息,或者建议其他方法在cake中执行上述操作 在执行GitPull方法时 您可以使用(非蛋糕解决方案)尝试(即fetch+merge) 或者,正如前面提到的 我看不到方法中支持的选项,因此您至少可以尝试分析以下结果: var result = GitLog("c:/temp/cake", 1); (这是由git pull生成的

您好,我正在使用GitPull方法将更改拉入存储库

参考下面的链接

我需要在执行GitPull方法时获取更新文件的日志

是否有任何方法可以使用下面的页面获取这些详细信息,或者建议其他方法在cake中执行上述操作

在执行GitPull方法时

您可以使用(非蛋糕解决方案)尝试(即fetch+merge)

或者,正如前面提到的

我看不到方法中支持的选项,因此您至少可以尝试分析以下结果:

var result = GitLog("c:/temp/cake", 1);

(这是由
git pull
生成的最后一次合并提交)

首先,由于Cake.git/Libgit2sharp中的合并之前存在问题,您需要升级到
0.14.0
或更高版本的
Cake.git
,才能使用此答案

无论是否快进合并,可靠获取更改文件的最简单方法是:

  • 在拉之前先提交
  • 如果回购协议不是最新的,请在拉后提交
  • 在拉入提交之前和之后进行区分
  • 这样做的
    Cake.Git
    方法是

  • 如果。!=。然后
  • 这可能看起来像下面这样

    #addin nuget:?package=Cake.Git&version=0.14.0
    
    DirectoryPath repoDir = MakeAbsolute(Directory("./Cake_Git"));
    
    string  name    = "John Doe",
            email   = "john@doe.com";
    
    var beforePullCommit = GitLogTip(repoDir);
    
    var pullResult = GitPull(repoDir, name, email);
    
    if (pullResult.Status!=GitMergeStatus.UpToDate)
    {
        var afterPullCommit = GitLogTip(repoDir);
    
        var diff = GitDiff(repoDir, beforePullCommit.Sha, afterPullCommit.Sha);
    
        foreach(var file in diff)
        {
            Information("{0}", file);
        }
    }
    
    返回具有这些属性的s的ICollection

    Name        Value           Summary
    Exists      bool            The file exists in the new side of the diff.
    OldExists   bool            The file exists in the old side of the diff.
    OldPath     string          The old path.
    Path        string          The new path.
    Status      GitChangeKind   The kind of change that has been done
                                (added, deleted, modified ...).
    
    并且有一个ToString()override sp,该脚本的输出如下所示

    Path: ReleaseNotes.md, OldPath: ReleaseNotes.md, Status: Modified, Exists: True, OldExists: True
    Path: src\Cake.Git\Cake.Git.csproj, OldPath: src\Cake.Git\Cake.Git.csproj, Status: Modified, Exists: True, OldExists: True
    Path: src\Cake.Git\GitMergeResult.cs, OldPath: src\Cake.Git\GitMergeResult.cs, Status: Modified, Exists: True, OldExists: True
    Path: src\Cake.Git\packages.config, OldPath: src\Cake.Git\packages.config, Status: Modified, Exists: True, OldExists: True
    Path: src\SolutionInfo.cs, OldPath: src\SolutionInfo.cs, Status: Modified, Exists: True, OldExists: True
    

    但是,由于它是一个类型化对象,您当然可以以更高的编程方式处理它

    Hi@Vonc当我在cmd中执行下面的命令时,它会生成日志
    git pull--stat>。/GitLogs/dashboard service.txt
    ,但同一个命令不会在c#或cakeCant中生成日志,而不能在c#
    字符串路径=@“G:\Gitlab\sfinput xaml”;System.IO.Directory.SetCurrentDirectory(路径);过程p=新过程();p、 StartInfo.FileName=@“C:\ProgramFiles\Git\bin\Git.exe”;p、 StartInfo.Arguments=“pull--stat>。/GitLogs/log.txt”;p、 StartInfo.RedirectStandardOutput=true;p、 StartInfo.UseShellExecute=false;p、 Start()错误:致命:'>../GitLogs/log.txt'似乎不是git存储库致命:无法从远程存储库读取。@JeevaS请确保您的进程在git repo路径中自行执行:我已将git存储库设置为当前目录。当我执行
    git clean-xdf
    命令时,它就工作了。。即使是
    git pull stat
    也可以工作。。但是当我试图编写面对上述问题的日志时。@JeevaS
    var startInfo=new ProcessStartInfo()
    startInfo.WorkingDirectory=//工作目录
    //设置其他属性
    Process proc=Process.Start(startInfo)
    
    Name        Value           Summary
    Exists      bool            The file exists in the new side of the diff.
    OldExists   bool            The file exists in the old side of the diff.
    OldPath     string          The old path.
    Path        string          The new path.
    Status      GitChangeKind   The kind of change that has been done
                                (added, deleted, modified ...).
    
    Path: ReleaseNotes.md, OldPath: ReleaseNotes.md, Status: Modified, Exists: True, OldExists: True
    Path: src\Cake.Git\Cake.Git.csproj, OldPath: src\Cake.Git\Cake.Git.csproj, Status: Modified, Exists: True, OldExists: True
    Path: src\Cake.Git\GitMergeResult.cs, OldPath: src\Cake.Git\GitMergeResult.cs, Status: Modified, Exists: True, OldExists: True
    Path: src\Cake.Git\packages.config, OldPath: src\Cake.Git\packages.config, Status: Modified, Exists: True, OldExists: True
    Path: src\SolutionInfo.cs, OldPath: src\SolutionInfo.cs, Status: Modified, Exists: True, OldExists: True