Need to get details of changed files in GitPull method in cake script

Hey. I am using the GitPull method to pull changes to the repository.

Link to below link

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

I need to get the log of the updated files when executing the GitPull method.

Is there a way to get this data using the page below or suggest another way to perform the above action in the cake.

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

+3


source to share


2 answers


First disclaimer due to a previous merge issue in Cake.Git / Libgit2sharp, you will need to upgrade to version 0.14.0

or later Cake.Git

for this answer to work.

The easiest way to reliably fetch files with changes, whether fast merge or not:

  • Get commit before push
  • Pull out
  • If the repo has not been updated Get commit after pull
  • Make the difference between before and after pull commit

Cake.Git

the way to do it would be

It might look something like this:



#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 GitDiffFile 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 ToString () override sp, the output of this script will 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 since it is a typed object you could of course do it in a much more programmatic way.

+3


source


when executing the GitPull method.

You can try after git pull (this is fetch plus merge), with (non-Cake solution)

git log --stat

      

Or, as mentioned in Entertainment withFETCH_HEAD



git log --name-only ..FETCH_HEAD

      

I don't see these options supported in Cake's GitLog , so you can try to at least parse the output:

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

      

(this is the last merge generated git pull

)

+1


source







All Articles