Repository.Reset doesn't checkout files having only a single line's line ending changed
If the line ending of only one line somewhere in the middle of a file, the file is not detected as Dirty by the reset method and the change is not reverted after calling it.
On the other hand Repository.RetrieveStatus correctly returns the file as modified
I'm attaching a test repo which shows the issue with version v0.22 from NuGet (Note that I had to change the zip file's extension to txt because otherwise GitHub rejected it for some reason...).
Can you provide some sample code that shows how you're calling RetrieveStatus and how you're calling Reset that causes this behavior?
Sure! Here it is:
using System;
using LibGit2Sharp;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (var repo = new Repository(@"C:\temp\test-repo"))
{
var status = repo.RetrieveStatus();
foreach (var se in status.Modified)
{
Console.WriteLine("{1}: {0}", se.FilePath, se.State);
}
repo.Reset(ResetMode.Hard, repo.Lookup<Commit>("HEAD"), new CheckoutOptions()
{
CheckoutModifiers = CheckoutModifiers.Force,
OnCheckoutProgress = (path, done, total) =>
{
Console.WriteLine("Reset progress: {0} {1}/{2}", path, done, total);
return;
},
CheckoutNotifyFlags = (CheckoutNotifyFlags) Enum.ToObject(typeof(CheckoutNotifyFlags), -1),
OnCheckoutNotify = (path, flags) =>
{
Console.WriteLine("Reset: {0}, flags: {1}", path, flags);
return true;
}
});
}
Console.ReadLine();
}
}
}
Actual output that I get is:
Modified: ObjectIdFixture.cs
Reset progress: 0/0
The reset should detect the file as modified and check it out into the working directory.
Hi, can you please confirm if you're able to reproduce the problem?
Yes, I can reproduce this, but I won't have any time to investigate in the immediate future.
This issue has just bitten me. I have a text file with LF line endings that is replaced with another file that has the exact same text, but the line endings are CRLF. Status identifies the file as modified but repo.Checkout(...) does not revert the file to its previous state. git checkout <file> on the commandline does.
I'm using libgit2sharp 0.27.0-preview-0175.