libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.12k stars 878 forks source link

Repository.Worktrees.Add leaves now worktree empty #2037

Open AArnott opened 1 year ago

AArnott commented 1 year ago

Somewhere in the 0.27.0-preview-0182 to 0.27.2 range, LibGit2Sharp broke creation of work trees.

Reproduction steps

Given a Repository object that points to a valid git repo with at least 2 commits in its history, call Repository.Worktrees.Add("HEAD~1", "myworktree", "../somePath", isLocked: false);

See this test method for a full repro.

Expected behavior

The worktree directory is created with a .git file and all files from the ref/commit that was specified when it was created.

Actual behavior

The worktree directory is created with a .git file in it, but otherwise it is empty.

Version of LibGit2Sharp (release number or SHA1)

0.27.0-preview-0182

Operating system(s) tested; .NET runtime tested

Windows Fails on .NET Framework 4.8 and .NET 7.

barry-bvl commented 1 month ago

Is there any update on this issue?

enriqueraso commented 1 month ago

@bording, @AArnott Any updates on this issue? 0.26.2 is the last release that creation of a worktree worked fine. I already tested with 0.30.0 and 0.29.0

enriqueraso commented 1 month ago

I forked LibGit2 repo and I found why the worktree is creating an empty folder (only .git file) and it is because current code does not contain the checkout_strategy is GIT_CHECKOUT_NONE when it was GIT_CHECKOUT_FORCE in version 02.26.2 (latest version that it works fine). This version is from 12/11/2019 and the image below is a diff between commits 5d5b76df (Committed by @ethomson on 24/06/2019 16:00:41) and latest commit 85f5aec1 (Committed by @ethomson on 05/03/2024 10:44:16).

image

Any reason for this change? There are two options to fix it.

1) Force it in worktree.c (LibGit2 project) (but it is passing in git_worktree_add_options).

2) Force it in WorktreeCollection.cs (LibGit2Sharp project)

ethomson commented 1 month ago

Thanks for the investigation @enriqueraso - this needs a fix in LibGit2Sharp.

ethomson commented 1 month ago

(IIUC that is - I think that the default opts structure for worktrees is wrong.)

enriqueraso commented 1 month ago

@ethomson ok, I will create a PR for it

enriqueraso commented 1 month ago

@ethomson @AArnott @bording, I created this PR https://github.com/libgit2/libgit2sharp/pull/2099 but I cannot assign you as reviewers.