Cake_Git
Cake_Git copied to clipboard
GitHasStagedChanges only considers modified files, not new/deleted/renamed
Looking at the source code for LibGit2Sharp's RepositoryStatus, it seems that the "Staged" list only contains existing files that were modified, not files that were added, deleted or renamed. These are stored in separate lists. https://github.com/libgit2/libgit2sharp/blob/f8e2d42ed9051fa5a5348c1a13d006f0cc069bc7/LibGit2Sharp/RepositoryStatus.cs#L42
return new Dictionary<FileStatus, Action<RepositoryStatus, StatusEntry>>
{
{ FileStatus.NewInWorkdir, (rs, s) => rs.untracked.Add(s) },
{ FileStatus.ModifiedInWorkdir, (rs, s) => rs.modified.Add(s) },
{ FileStatus.DeletedFromWorkdir, (rs, s) => rs.missing.Add(s) },
{ FileStatus.NewInIndex, (rs, s) => rs.added.Add(s) },
{ FileStatus.ModifiedInIndex, (rs, s) => rs.staged.Add(s) },
{ FileStatus.DeletedFromIndex, (rs, s) => rs.removed.Add(s) },
{ FileStatus.RenamedInIndex, (rs, s) => rs.renamedInIndex.Add(s) },
{ FileStatus.Ignored, (rs, s) => rs.ignored.Add(s) },
{ FileStatus.RenamedInWorkdir, (rs, s) => rs.renamedInWorkDir.Add(s) },
};
}
The Cake.Git method GitAliases.Repository.GitHasStagedChanges only checks the RepositoryStatus.Staged list, not the NewInIndex, DeletedFromIndex, RenamedInIndex. https://github.com/cake-contrib/Cake_Git/blob/ad0b56e6a8b53fcda9f1178f5a9953eff9f9d322/src/Cake.Git/GitAliases.Repository.cs#L101-L121
So if your changes only contain new files/deleted files/renamed files, GitHasStagedChanges
will return false
.
I'm not an expert on Git terminology, but I believe "staged" means any changes staged for commit, not just modified files?
If so, I guess it's a matter of discussion where the error lies, LibGit2Sharp's naming of the Staged-list is maybe a bit unfortunate, but I also guess that Cake.Git is consuming the RepositoryStatus "API" wrongly?