Question

In libgit2sharp https://github.com/libgit2/libgit2sharp/ how do you check for pending/uncommitted changes?

Was it helpful?

Solution

The following works for me:

///DEPRECATED - see comment from @derptastic
public bool HasUncommittedChanges
{
    get
    {
        using (var repo = new Repository(repositoryRoot))
        {
            RepositoryStatus status = repo.RetrieveStatus();
            return status.IsDirty;
        }
    }
}

Thanks to @Derptastic for the link to LibGit2Sharp Wiki

OTHER TIPS

The following lines of code will provide the filename and the state of that file.

foreach (var item in repo1.RetrieveStatus())
{
  Console.WriteLine(item.FilePath);
  Console.WriteLine(item.State);
}    

You can use repository.Diff.Compare().

    /// <summary>
    ///   Show changes between the working directory and the index.
    /// </summary>
    /// <param name = "paths">The list of paths (either files or directories) that should be compared.</param>
    /// <returns>A <see cref = "TreeChanges"/> containing the changes between the working directory and the index.</returns>
    public virtual TreeChanges Compare(IEnumerable<string> paths = null)

Passing no paths at all should give all changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top