您好,我正在使用 GitPull 方法将更改 pull 入存储库。
从下面的链接引用
http://cakebuild.net/api/Cake.Git/GitAliases/CC1AE32F
我需要在执行 GitPull 方法时获取更新文件的日志。
是否有任何方法可以使用下面的页面获取这些详细信息,或者建议使用其他方法在蛋糕中执行上述操作。
最佳答案
首先是一个免责声明,因为之前在 Cake.Git/Libgit2sharp 中存在 merge 问题,您需要升级到 0.14.0
或更高版本的 Cake.Git
使这个答案起作用。
无论是否进行快进 merge ,可靠地获取更改文件的最简单方法是:
- pull 前获取提交
- pull
- 如果 repo 不是最新的, pull 后获取提交
- 在 pull 提交之前和之后做一个差异
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返回 GitDiffFile 的 ICollection具有这些属性的 s。
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# - 需要在cake脚本的GitPull方法中获取修改文件的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42918647/