本文整理汇总了Java中org.eclipse.jgit.api.Git.cloneRepository方法的典型用法代码示例。如果您正苦于以下问题:Java Git.cloneRepository方法的具体用法?Java Git.cloneRepository怎么用?Java Git.cloneRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.api.Git
的用法示例。
在下文中一共展示了Git.cloneRepository方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
/**
* 从指定的git仓库地址(目前仅支持http和https)和文件名获取资源,通过UsernameCredential支持鉴权
* @return 资源的字符串
* @throws Exception 资源不存在或网络不通
*/
@Override
public String load() throws Exception {
//本地临时目录,用户存放clone的代码
String tempDirPath = localPath + "/iaac.aliyun.tmp_" + new Date().getTime();
File tempDir = new File(tempDirPath);
tempDir.mkdirs();
String result = null;
try {
CloneCommand clone = Git.cloneRepository();
clone.setURI(url);
clone.setBranch(this.branch);
clone.setDirectory(tempDir);
//设置鉴权
if (this.credential != null) {
UsernamePasswordCredentialsProvider usernamePasswordCredentialsProvider = new
UsernamePasswordCredentialsProvider(this.credential.getUsername(), this.credential.getPassword());
//git仓库地址
clone.setCredentialsProvider(usernamePasswordCredentialsProvider);
}
//执行clone
Git git = clone.call();
//从本地路径中获取指定的文件
File file = new File(tempDir.getAbsolutePath() + "/" + this.fileName);
//返回文件的字符串
result = FileUtils.readFileToString(file, "utf-8");
} catch (Exception e) {
throw e;
} finally {
//清除本地的git临时目录
FileUtils.deleteDirectory(tempDir);
}
return result;
}
示例2: cloneRepo
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider,
final File sshPrivateKey, final File sshPublicKey, String remote, String tag) {
StopWatch watch = new StopWatch();
// clone the repo!
boolean cloneAll = true;
LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath()
+ " cloneAllBranches: " + cloneAll);
CloneCommand command = Git.cloneRepository();
GitUtils.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey);
command = command.setCredentialsProvider(credentialsProvider).
setCloneAllBranches(cloneAll).setURI(cloneUrl).setDirectory(projectFolder).setRemote(remote);
try {
Git git = command.call();
if (tag != null) {
git.checkout().setName(tag).call();
}
} catch (Throwable e) {
LOG.error("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage(), e);
throw new RuntimeException("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage());
} finally {
LOG.debug("cloneRepo took " + watch.taken());
}
}
示例3: cloneRepo
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public boolean cloneRepo( String directory, String uri ) {
CloneCommand cmd = Git.cloneRepository();
cmd.setDirectory( new File( directory ) );
cmd.setURI( uri );
cmd.setCredentialsProvider( credentialsProvider );
try {
Git git = cmd.call();
git.close();
return true;
} catch ( Exception e ) {
if ( ( e instanceof TransportException )
&& ( ( e.getMessage().contains( "Authentication is required but no CredentialsProvider has been registered" )
|| e.getMessage().contains( "not authorized" ) ) ) ) {
if ( promptUsernamePassword() ) {
return cloneRepo( directory, uri );
}
} else {
showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() );
}
}
return false;
}
示例4: cloneRepo
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public Git cloneRepo(CloneRepoAttributes attributes) throws GitAPIException {
CloneCommand command = Git.cloneRepository();
String gitUri = attributes.getUri();
UserDetails userDetails = attributes.getUserDetails();
CredentialsProvider credentialsProvider = userDetails.createCredentialsProvider();
GitUtils.configureCommand(command, credentialsProvider, userDetails.getSshPrivateKey(), userDetails.getSshPublicKey());
command = command.setCredentialsProvider(credentialsProvider).
setCloneAllBranches(attributes.isCloneAll()).
setURI(gitUri).
setDirectory(attributes.getDirectory()).setRemote(attributes.getRemote());
return command.call();
}
示例5: GitRepoCloner
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public GitRepoCloner() {
cloneCommand = Git.cloneRepository();
}