本文整理汇总了Java中org.eclipse.jgit.api.Git.getRepository方法的典型用法代码示例。如果您正苦于以下问题:Java Git.getRepository方法的具体用法?Java Git.getRepository怎么用?Java Git.getRepository使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.api.Git
的用法示例。
在下文中一共展示了Git.getRepository方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GitTool
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public GitTool() {
File gitWorkDir = new File(".");
try {
Git git = Git.open(gitWorkDir);
Iterable<RevCommit> commits = git.log().all().call();
Repository repo = git.getRepository();
branch = repo.getBranch();
RevCommit latestCommit = commits.iterator().next();
name = latestCommit.getName();
message = latestCommit.getFullMessage();
} catch (Throwable e) {
name = "";
message = "";
branch = "";
}
}
示例2: parserForBranch
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
private CanonicalTreeParser parserForBranch(Git git, Ref branch) throws IOException {
try (RevWalk walk = new RevWalk(git.getRepository())) {
RevCommit commit = walk.parseCommit(branch.getObjectId());
RevTree tree = walk.parseTree(commit.getTree().getId());
final CanonicalTreeParser parser;
try (ObjectReader reader = git.getRepository().newObjectReader()) {
parser = parser(reader, tree.getId());
}
walk.dispose();
return parser;
}
}
示例3: cloneIfNotExists
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public Repository cloneIfNotExists(String projectPath, String cloneUrl/* , String branch */) throws Exception {
File folder = new File(projectPath);
Repository repository;
if (folder.exists()) {
RepositoryBuilder builder = new RepositoryBuilder();
repository = builder
.setGitDir(new File(folder, ".git"))
.readEnvironment()
.findGitDir()
.build();
// logger.info("Project {} is already cloned, current branch is {}", cloneUrl, repository.getBranch());
} else {
Git git = Git.cloneRepository()
.setDirectory(folder)
.setURI(cloneUrl)
.setCloneAllBranches(true)
.call();
repository = git.getRepository();
// logger.info("Done cloning {}, current branch is {}", cloneUrl, repository.getBranch());
}
// if (branch != null && !repository.getBranch().equals(branch)) {
// Git git = new Git(repository);
//
// String localBranch = "refs/heads/" + branch;
// List<Ref> refs = git.branchList().call();
// boolean branchExists = false;
// for (Ref ref : refs) {
// if (ref.getName().equals(localBranch)) {
// branchExists = true;
// }
// }
//
// if (branchExists) {
// git.checkout()
// .setName(branch)
// .call();
// } else {
// git.checkout()
// .setCreateBranch(true)
// .setName(branch)
// .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
// .setStartPoint("origin/" + branch)
// .call();
// }
//
// logger.info("Project {} switched to {}", cloneUrl, repository.getBranch());
// }
return repository;
}
示例4: cloneIfNotExists
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
@Override
public Repository cloneIfNotExists(String projectPath, String cloneUrl/*, String branch*/) throws Exception {
File folder = new File(projectPath);
Repository repository;
if (folder.exists()) {
RepositoryBuilder builder = new RepositoryBuilder();
repository = builder
.setGitDir(new File(folder, ".git"))
.readEnvironment()
.findGitDir()
.build();
//logger.info("Project {} is already cloned, current branch is {}", cloneUrl, repository.getBranch());
} else {
logger.info("Cloning {} ...", cloneUrl);
Git git = Git.cloneRepository()
.setDirectory(folder)
.setURI(cloneUrl)
.setCloneAllBranches(true)
.call();
repository = git.getRepository();
//logger.info("Done cloning {}, current branch is {}", cloneUrl, repository.getBranch());
}
// if (branch != null && !repository.getBranch().equals(branch)) {
// Git git = new Git(repository);
//
// String localBranch = "refs/heads/" + branch;
// List<Ref> refs = git.branchList().call();
// boolean branchExists = false;
// for (Ref ref : refs) {
// if (ref.getName().equals(localBranch)) {
// branchExists = true;
// }
// }
//
// if (branchExists) {
// git.checkout()
// .setName(branch)
// .call();
// } else {
// git.checkout()
// .setCreateBranch(true)
// .setName(branch)
// .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
// .setStartPoint("origin/" + branch)
// .call();
// }
//
// logger.info("Project {} switched to {}", cloneUrl, repository.getBranch());
// }
return repository;
}