Commands.Stage() 在使用 LibGit2Sharp 暂存未跟踪文件时不会增加 Staged.Count
Commands.Stage() doesn't increment Staged.Count when staging untracked files with LibGit2Sharp
当我暂存至少一个跟踪文件时,以下块有效。但是当我只暂存未跟踪的文件时,repo.RetrieveStatus().Staged.Count
等于零(我希望它会随着暂存文件的数量增加),因此不满足 if 条件并且不提交。
using (var repo = new LibGit2Sharp.Repository(RepoPath))
{
Commands.Stage("*");
Signature author = new Signature(username, email, DateTime.Now);
Signature committer = author;
if (repo.RetrieveStatus().Staged.Any())
{
Commit commit = repo.Commit(CommitMessage, author, committer);
Console.WriteLine(commit.ToString());
}
}
这是一个错误,还是我误用了它?
Staged
集合的定义是:
List of files added to the index, which are already in the current commit with different content
即这些对应git-status
的"changes to be committed"区的"modified",或者git-status --short
的M
状态。
根据定义,这些文件不包括暂存的新添加文件。为此,您还需要检查 Added
集合,即:
List of files added to the index, which are not in the current commit
即这些对应git-status
的"changes to be committed"区的"new files",或git status --short
的A
状态。
但是,您可能还想考虑 所有 分阶段更改,我认为这正是您想要做的。你会想看看这些集合的状态:
Added
: List of files added to the index, which are not in the current commit
Staged
: List of files added to the index, which are already in the current commit with different content
Removed
: List of files removed from the index but are existent in the current commit
RenamedInIndex
: List of files that were renamed and staged (if you requested renames).
目前没有任何功能可以 return 列出所有分阶段更改的列表,这似乎是一种疏忽(如果您想提交拉取请求到LibGit2Sharp!)
当我暂存至少一个跟踪文件时,以下块有效。但是当我只暂存未跟踪的文件时,repo.RetrieveStatus().Staged.Count
等于零(我希望它会随着暂存文件的数量增加),因此不满足 if 条件并且不提交。
using (var repo = new LibGit2Sharp.Repository(RepoPath))
{
Commands.Stage("*");
Signature author = new Signature(username, email, DateTime.Now);
Signature committer = author;
if (repo.RetrieveStatus().Staged.Any())
{
Commit commit = repo.Commit(CommitMessage, author, committer);
Console.WriteLine(commit.ToString());
}
}
这是一个错误,还是我误用了它?
Staged
集合的定义是:
List of files added to the index, which are already in the current commit with different content
即这些对应git-status
的"changes to be committed"区的"modified",或者git-status --short
的M
状态。
根据定义,这些文件不包括暂存的新添加文件。为此,您还需要检查 Added
集合,即:
List of files added to the index, which are not in the current commit
即这些对应git-status
的"changes to be committed"区的"new files",或git status --short
的A
状态。
但是,您可能还想考虑 所有 分阶段更改,我认为这正是您想要做的。你会想看看这些集合的状态:
Added
: List of files added to the index, which are not in the current commit
Staged
: List of files added to the index, which are already in the current commit with different content
Removed
: List of files removed from the index but are existent in the current commit
RenamedInIndex
: List of files that were renamed and staged (if you requested renames).
目前没有任何功能可以 return 列出所有分阶段更改的列表,这似乎是一种疏忽(如果您想提交拉取请求到LibGit2Sharp!)