Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository.Worktrees.Add leaves now worktree empty #2037

Open
AArnott opened this issue May 11, 2023 · 7 comments
Open

Repository.Worktrees.Add leaves now worktree empty #2037

AArnott opened this issue May 11, 2023 · 7 comments

Comments

@AArnott
Copy link
Contributor

AArnott commented May 11, 2023

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
Copy link

Is there any update on this issue?

@enriqueraso
Copy link

@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
Copy link

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
Copy link
Member

ethomson commented Jun 3, 2024

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

@ethomson
Copy link
Member

ethomson commented Jun 3, 2024

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

@enriqueraso
Copy link

@ethomson ok, I will create a PR for it

@enriqueraso
Copy link

@ethomson @AArnott @bording, I created this PR #2099 but I cannot assign you as reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants