-1

I'm trying my best to figure out how to unstage a file with libgit2sharp.

My current approach is to to remove the file from the index, but that seems to delete the file instead of unstaging it.

        public bool Unstage(params string[] filePaths)
    {
        using (var repo = LocalRepo)
        {
            try
            {
                foreach (var filePath in filePaths)
                {
                    repo.Index.Remove(filePath);
                    repo.Index.Write();
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        return true;
    }

I've tried to do a soft reset as well, but I can't figure out how to pass in the filename or use the commitish parameter in one of the reset function overloads.

Been trying to follow this post: Why are there two ways to unstage a file in Git?, but I can't seem to figure out how to recreate that approach in libgit2sharp.

The Pax Bisonica
  • 2,154
  • 2
  • 26
  • 45

1 Answers1

1

After searching for quite some time, I finally found out that libgit2sharp has a Commands static class with almost every command you would need built in and ended up doing it like this:

      public bool Unstage(params string[] filePaths)
    {
        using (var repo = LocalRepo)
        {
            try
            {
                foreach (var filePath in filePaths)
                {
                   Commands.Unstage(repo, filePath);
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        return true;
    }
The Pax Bisonica
  • 2,154
  • 2
  • 26
  • 45