First a disclaimer because of an previous issue with merges in Cake.Git / Libgit2sharp you'll need to upgrade to version 0.14.0
or later of Cake.Git
for this answer to work.
Easiest way to get changes files reliably regardless of fast forward merge or not is to:
- Get commit before pull
- Do the pull
- If repo wasn't up to date Get commit after pull
- Do a diff between before and after pull commit
The Cake.Git
way of doing this would be
- GitLogTip
- GitPull
- If pullResult.Status!=GitMergeStatus.UpToDate then GitLogTip
- GitDiff
This could look something like below
#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 returns an ICollection of GitDiffFiles which has these properties.
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 ...).
and has an ToString() override sp the output of this script would look something like this
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
but as it's an typed object you could do of course to a lot more programmatically.