在libgit2sharp中,如何检查是否存在未提交的更改?
在https://github.com/libgit2/libgit2sharp/中,如何检查待处理/未提交的更改?
以下方法适用于我:
///DEPRECATED - see comment from @derptastic
public bool HasUncommittedChanges
{
get
{
using (var repo = new Repository(repositoryRoot))
{
RepositoryStatus status = repo.RetrieveStatus();
return status.IsDirty;
}
}
}
感谢 @Derptastic 提供的链接到 LibGit2Sharp Wiki
repo.isDirty
返回 true。如果你想要一个简单的布尔检查来判断 Git diff(或者本质上是“我有未提交的更改吗”),可以参考官方文档 - https://github.com/libgit2/libgit2sharp/wiki/git-diff - repo.Diff.Compare<TreeChanges>().Count > 0
- Derptasticforeach (var item in repo1.RetrieveStatus())
{
Console.WriteLine(item.FilePath);
Console.WriteLine(item.State);
}
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)
没有传递任何路径应该显示所有更改。
RepositoryStatus status = repo.Index.RetrieveStatus();
方法的更多信息,详见单元测试。 - nemesv