libgit2 / libgit2/libgit2sharp

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

Open
#1,961 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.5k
Forks
925
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Worktrees.Add entry point and reproduce the failure with the feature/branch-name branch described in the issue on Windows. Trace the worktree directory creation and verify that adding a branch containing a slash completes without the reported exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.