libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

Repository.Reset doesn't checkout files having only a single line's line ending changed

Open mbektchiev opened this issue 9 years ago • 5 comments

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...).

test-repo.zip.txt

mbektchiev avatar Jun 17 '16 15:06 mbektchiev

Can you provide some sample code that shows how you're calling RetrieveStatus and how you're calling Reset that causes this behavior?

ethomson avatar Jun 17 '16 15:06 ethomson

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.

mbektchiev avatar Jun 20 '16 07:06 mbektchiev

Hi, can you please confirm if you're able to reproduce the problem?

mbektchiev avatar Jun 29 '16 08:06 mbektchiev

Yes, I can reproduce this, but I won't have any time to investigate in the immediate future.

ethomson avatar Jun 29 '16 17:06 ethomson

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.

vyfster avatar May 14 '22 00:05 vyfster