Clone a GIT repository with NGit in VB.net

418 views Asked by At

My objective is to perform clone and pull operations on a GIT repository through .NET code. When cloning, I specifically want to clone a particular branch. If a particular repository is already cloned but with a different branch, then I would like to be able to know it as well.

I had implemented this with jGit in Java successfully, but now I need to develop a similar tool in .NET and I prefer using NGit since it is a direct port of jGIT library.

However, though I use the exact methods passing the relevant parameters to the clone method in NGit, I don't see repository getting downloaded. Below is my code:

Dim branches As List(Of String) = New List(Of String) From {branch}
Git.CloneRepository.
    SetURI(cloneURL).
    SetDirectory(New Sharpen.FilePath(downloadFolder)).  
    SetBranchesToClone(branches).
    SetCredentialsProvider(New UsernamePasswordCredentialsProvider(userID, userPwd)).
    SetBranch(branch).
    Call()

When I run this, it takes few seconds and there are no errors. But in the download folder I see there is only a .git folder with some meta data and the source files are not downloaded. If I remove SetBranchesToClone and SetBranch methods from the above code, it downloads files successfully from master branch.

Why doesn't it work when branch info is provided?

1

There are 1 answers

0
Shiridish On BEST ANSWER

I figured out that while in jGit you can use the exact branch name like MyBranch, in case of NGit you need to pass refs/heads/MyBranch for it work. Apparently though nGit claims to be an automatic port of jGit, there are some minor differences in how they work.