Skip to content

WorktreeCollection.Add throws exception on NET6 Preview 4 (0.27.0-preview-0096) #1885

Closed
@DvdKhl

Description

@DvdKhl

Reproduction steps

  • Download and open attached Project
  • Set target framework to net6 and run the project

Expected behavior

Worktrees.Add executes without exception

Actual behavior

Throws "LibGit2Sharp.LibGit2SharpException: reference is not a branch".

Version of LibGit2Sharp (release number or SHA1)

0.27.0-preview-0096

Operating system(s) tested; .NET runtime tested

Windows 10 Version 2004 (OS Build 19041.985) x64

using LibGit2Sharp;
using System;
using System.IO;
using System.Linq;
namespace LibGit2SharpWorktreeIssue {
  class Program {
    static void Main(string[] args) {
      var mainRepoPath = Path.Combine("..", "RepoTest", "Main");
      using(var repo = new Repository(mainRepoPath)) {
        try {
          var branchName = "r" + DateTimeOffset.Now.ToUnixTimeSeconds();
          var workTreePath = Path.GetFullPath(Path.Combine(mainRepoPath, "..", branchName));
          //While debugging retry this line. It often works the second time.
          var newWorkTree = repo.Worktrees.Add(branchName, workTreePath, false);
        } catch(Exception ex) {
          Console.WriteLine(ex);
        }
      }
    }
  }
}

LibGit2SharpWorktreeIssue.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions