libgit2 / libgit2sharp

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

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

Open TureyLab opened 2 years ago

TureyLab commented 2 years ago

Reproduction steps

have a repository with the branches

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

maui1911 commented 3 months ago

I have this same issue :(