libgit2sharp
libgit2sharp copied to clipboard
Repository.Worktrees.Add leaves now worktree empty
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.
Is there any update on this issue?
@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
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).
Any reason for this change? There are two options to fix it.
-
Force it in worktree.c (LibGit2 project) (but it is passing in git_worktree_add_options).
-
Force it in WorktreeCollection.cs (LibGit2Sharp project)
Thanks for the investigation @enriqueraso - this needs a fix in LibGit2Sharp.
(IIUC that is - I think that the default opts structure for worktrees is wrong.)
@ethomson ok, I will create a PR for it
@ethomson @AArnott @bording, I created this PR https://github.com/libgit2/libgit2sharp/pull/2099 but I cannot assign you as reviewers.