libgit2 / libgit2/libgit2sharp

Libgit2sharp CheckoutPaths() doesn't undo changes on file with status "NewInIndex, ModifiedInWorkdir".

Open
#1,984 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.5k
Forks
925
PR merge metrics
No merged PRs in 30d

Description

You are opening a bug report against the LibGit2Sharp project: we
use GitHub Issues for tracking bug reports and feature requests. If
you have a question about an API or usage, please ask on StackOverflow:
http://stackoverflow.com/questions/tagged/libgit2sharp.

Otherwise, to report a bug, please fill out the reproduction steps
(below) and delete these introductory paragraphs. Thanks!

Reproduction steps

I have a file inside many folders (for ex : docs/jsons/myfile.json ) in my repository

I staged the file , so it now has the status "NewInIndex".

After that i made changes on that file.

It has now the status "NewInIndex, ModifiedInWorkdir".

My code is the following :

using ( var repo = new Repository("my repo path")
{
CheckoutOptions options = new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force };

repo.CheckoutPaths(repo.Head.FriendlyName, new string[] {"docs/jsons/myfile.json"} , options );
}

I also tried to replace " repo.Head.FriendlyName" by "repo.Head.CannonicalName" and by "repo.Head.Tip.Id.Sha"

Expected behavior

I expect the file to get back to its previous content, and to have the status "NewInIndex" again.

Actual behavior

The file's content doesnt change and its status is still : "NewInIndex, ModifiedInWorkdir".

Version of LibGit2Sharp (release number or SHA1)

LibGit2Sharp version 0.26.2

Operating system(s) tested; .NET runtime tested

Window 10 Enterprise

.NET 6.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CheckoutPaths API and reproduce the reported state transition for a file marked NewInIndex, ModifiedInWorkdir using the supplied path and CheckoutOptions. Verify that forcing checkout restores the staged content and leaves the file with NewInIndex status, using the reported LibGit2Sharp 0.26.2 behavior as the baseline.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.