当前位置: 首页>>代码示例>>Java>>正文


Java Git.getRepository方法代码示例

本文整理汇总了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 = "";
    }
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:17,代码来源:GitTool.java

示例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;
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:16,代码来源:CurioGenericCiPlugin.java

示例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;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:53,代码来源:GitHelper.java

示例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;
	}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:55,代码来源:GitServiceImpl.java


注:本文中的org.eclipse.jgit.api.Git.getRepository方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。