需要在Cake脚本中的GitPull方法中获取修改后的文件的详细信息
问题描述:
您好我正在使用GitPull方法将更改拉入存储库。需要在Cake脚本中的GitPull方法中获取修改后的文件的详细信息
从下面的链接
http://cakebuild.net/api/Cake.Git/GitAliases/CC1AE32F
提到我需要在执行GitPull方法来获取更新文件的日志。
有没有什么方法可以使用下面的页面来获取这些细节,或者建议其他方式来在蛋糕中执行上述操作。
答
while performing GitPull method.
你可以尝试after a git pull(这是获取加上合并),用(非蛋糕溶液)
git log --stat
git log --name-only ..FETCH_HEAD
提到
我看不到支持的选项方法,所以你可以尝试至少解析的结果:
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 = "[email protected]";
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 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()重写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
,但因为它是一个类型的对象,你可以更多的编程做当然了不少。
@Vonc您好 当我在CMD执行以下命令它产生的日志 'GIT中拉--stat> ../ GitLogs /仪表板service.txt' 但相同的命令不会产生登录C#或蛋糕 –
@JeevaS它是什么产生的? (当在蛋糕中完成时) – VonC
不能在c中执行它# 'string path = @“G:\ Gitlab \ sfinput-xaml”; System.IO.Directory.SetCurrentDirectory(path); Process p = new Process(); p.StartInfo.FileName = @“C:\ Program Files \ 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仓库 致命:无法从远程存储库中读取** –