libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

Git worktree not supported by Repository object

Open jjcole opened this issue 11 years ago • 4 comments

It seems like "git worktree" introduced in Git 2.5 is not supported by the library. If I try to create a Repository object with my worktree directory, or with the file path directly to the ".git" file, it says it's not a valid Git repository.

For example, I have C:\Code\Main and I use "git worktree" to create a worktree at C:\Code\Fix. I am not able to create a Repository object if I pass in either "C:\Code\Fix" or "C:\Code\Fix.git". It also doesn't work if I pull the gitdir out of the .git file (C:\Code\Main\worktrees\Fix) and pass that into the Repository constructor. (Git Extensions correctly handles the worktree so I don't believe there's any other issue at play.)

Apologies if this is covered somewhere else or if I'm just doing something wrong, Google search wasn't very helpful and the term worktree didn't bring up anything here in Issues.

I tried working around by setting IndexPath and WorkingDirectoryPath in RepositoryOptions, but it still uses the current HEAD of the original repo at C:\Code\Main instead of the one in C:\Code\Fix.

More details on git worktree: https://git-scm.com/docs/git-worktree https://github.com/blog/2042-git-2-5-including-multiple-worktrees-and-triangular-workflows

jjcole avatar Nov 02 '15 21:11 jjcole

Indeed, this is not yet supported. Work is going on in https://github.com/libgit2/libgit2/pull/3436

ethomson avatar Nov 02 '15 21:11 ethomson

My mistake for not checking libgit2 first, thanks.

jjcole avatar Nov 02 '15 21:11 jjcole

Now, libgit2/libgit2#3436 has been merged.

s-yasu avatar Feb 15 '17 13:02 s-yasu

Hi Folk can you please refer sample documentation or code snapshot to create WorkTree Programatically.

kpvnreddy avatar Aug 04 '17 10:08 kpvnreddy