[英]Clone a GIT repository with NGit in VB.net
My objective is to perform clone and pull operations on a GIT
repository through .NET
code. 我的目标是通过.NET
代码在GIT
存储库上执行克隆和提取操作。 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. 我已经用Java在jGit
中成功实现了此jGit
,但是现在我需要在.NET
开发类似的工具,并且我更喜欢使用NGit
因为它是jGIT
库的直接端口。
However, though I use the exact methods passing the relevant parameters to the clone method in NGit
, I don't see repository getting downloaded. 但是,尽管我使用了将相关参数传递给NGit
的clone方法的精确方法,但是我看不到存储库正在下载。 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. 但是在下载文件夹中,我看到只有.git
文件夹包含一些元数据,并且未下载源文件。 If I remove SetBranchesToClone
and SetBranch
methods from the above code, it downloads files successfully from master branch. 如果我从上面的代码中删除SetBranchesToClone
和SetBranch
方法,它将成功从master分支下载文件。
Why doesn't it work when branch info is provided? 提供分支机构信息后为什么不起作用?
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. 我发现在jGit中可以使用确切的分支名称,例如MyBranch
,在NGit的情况下,您需要传递refs/heads/MyBranch
才能起作用。 Apparently though nGit claims to be an automatic port of jGit, there are some minor differences in how they work. 显然,尽管nGit声称是jGit的自动端口,但它们的工作方式还是有一些细微的差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.