编程语言
首页 > 编程语言> > c# – 需要在蛋糕脚本中的GitPull方法中获取修改文件的详细信息

c# – 需要在蛋糕脚本中的GitPull方法中获取修改文件的详细信息

作者:互联网

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

从以下链接引用

http://cakebuild.net/api/Cake.Git/GitAliases/CC1AE32F

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

有没有办法使用下面的页面获取这些细节或建议一些其他方式在蛋糕上执行上述操作.

http://cakebuild.net/dsl/git/

解决方法:

首先是免责声明,因为之前在Cake.Git / Libgit2sharp中进行合并的问题,您需要升级到Cake.Git版本0.14.0或更高版本才能使此答案正常工作.

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

>拉前获取提交
>拉扯
>如果repo不是最新的,请在拉后提交
>在pull commit之前和之后做一个diff

Cake.Git这样做的方法是

> GitLogTip
> GitPull
>如果pullResult.Status!= GitMergeStatus.UpToDate然后是GitLogTip
> GitDiff

这看起来像下面的内容

#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);
    }
}

GitDiff返回具有这些属性的ICollection GitDiffFiles.

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()覆盖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

但是因为它是一个打字对象,你当然可以通过编程方式进行更多操作.

标签:c,git,libgit2sharp,cakebuild
来源: https://codeday.me/bug/20190622/1265675.html