libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

Worktrees.Add throws an exception if a slash is in the branch name

Open TureyLab opened this issue 3 years ago • 1 comments

Reproduction steps

have a repository with the branches

  • main [default]
  • feature/branch-name

Clone the repository and add the worktree.

SourceCode:

               var cloneOptions = new CloneOptions()
                {
                    CredentialsProvider = (_url, _user, _cred) => this.Credentials,                    
                    Checkout = true,
                    RecurseSubmodules = true,
                };
                 
                this.gitRepositoryPath = Repository.Clone(this.SourceUrl, this.WorkdirPath, cloneOptions);
                
                using (var repo = new Repository(this.gitRepositoryPath))
                {
                    var path = Path.Combine(this.WorkdirPath, "..", this.Branch);

                    repo.Worktrees.Add(this.Branch, path, false);
                }   

Expected behavior

Worktree should be created

Actual behavior

Exception is thrown: failed to make directory 'xxx/.git/worktrees/feature/branch-name': The system cannot find the path specified.

Version of LibGit2Sharp (release number or SHA1)

0,26, 0.27.0-preview-0182

Operating system(s) tested; .NET runtime tested

Windows 10, Windows Server 2016, .Net Framework 4.8

TureyLab avatar Apr 22 '22 09:04 TureyLab

I have this same issue :(

maui1911 avatar Jun 20 '24 07:06 maui1911