LibGit2Sharp repo.Index.Stage()
relies on libgit2 diffing functionality to determine which files have been modified in the workdir and which files haven't.
When doing a diff, and before comparing the actual files contents, libgit2 relies on some "tricks" to check if a file has been changed. For example:
- if the file has the same size in the index and in the workdir
- and if the file modification date/time is the same (time with seconds precision on windows)
- and if other attributes (file owner, mode, ...) are the same
then the file is considered as unmodified, and it won't be opened at all to see if the content is the same. This allows for a big optimization for big repos with thousands of files.
In your case, many of your files have the same size and the same date/time of modification, which is why those files are not picked up by repo.Index.Stage()
.
A possible (dirty) workaround is to add a Thread.Sleep(TimeSpan.FromSeconds(1));
between your modifications.
A bug report dealing with the same issue has recently been opened on the LibGit2Sharp bugtracker. If you have real-world examples, or an opinion to give, on this topic, feel free to weigh in!