对于 LibGit2Sharp,Status 命令是否应该显示已提交但尚未推送的更改?

With LibGit2Sharp, should the Status command show changes that are committed, but not yet pushed?

我有一个存储库,其中目前有两个文件。我对一个文件进行了更改,并提交了更改,但尚未推送。当我从命令行 运行 'git status' 时,我得到以下信息:

On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

这符合预期。

我在 C# 中有一些代码可以获取存储库的状态,如下所示:

using (Repository repo = new Repository(localRepoFolder))
{
    RepositoryStatus status = repo.RetrieveStatus();
}

当我单步执行代码并转储 status 变量时,我得到以下信息:

status
+0 ~0 -0 | +0 ~0 -0 | i0
Added: Count = 0
DebuggerDisplay: "+0 ~0 -0 | +0 ~0 -0 | i0"
Ignored: Count = 0
IsDirty: false
Missing: Count = 0
Modified: Count = 0
Removed: Count = 0
RenamedInIndex: Count = 0
RenamedInWorkDir: Count = 0
Staged: Count = 0
Unaltered: Count = 0
Untracked: Count = 0
added: Count = 0
dispatcher: Count = 9
ignored: Count = 0
isDirty: false
missing: Count = 0
modified: Count = 0
removed: Count = 0
renamedInIndex: Count = 0
renamedInWorkDir: Count = 0
staged: Count = 0
statusEntries: Count = 0
unaltered: Count = 0
untracked: Count = 0
Results View: Expanding the Results View will enumerate the IEnumerable

它似乎没有像命令行那样显示本地和远程之间的区别。如何让它显示与命令行状态命令相同?

Status 只为您提供存储库的实际状态 - HEAD 和索引之间的差异,以及索引和工作目录之间的差异。它不包括任何其他元数据,例如 ahead/behind 计数。

如果您想知道您的分支与其跟踪分支的关系,那么您可以查看该分支的TrackingDetails。例如:

Console.WriteLine("Your branch is ahead of '{0}' by {1} commits and behind by {2} commits.",
    branch.TrackingBranch.CanonicalName,
    branch.TrackingDetails.AheadBy,
    branch.TrackingDetails.BehindBy);