本文整理汇总了Java中org.eclipse.jgit.api.Git.open方法的典型用法代码示例。如果您正苦于以下问题:Java Git.open方法的具体用法?Java Git.open怎么用?Java Git.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.api.Git
的用法示例。
在下文中一共展示了Git.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: should_push_success
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
@Test
public void should_push_success() throws Throwable {
File localGitFolder = folder.newFolder("info.git");
// when: init bareGit
JGitUtil.init(localGitFolder.toPath(), true);
// then: tag list is 0
Assert.assertEquals(0, Git.open(localGitFolder).tagList().call().size());
File onlineGitFolder = folder.newFolder("info");
JGitUtil.clone(GIT_URL, onlineGitFolder.toPath());
JGitUtil.remoteSet(onlineGitFolder.toPath(), "local", localGitFolder.toString());
Git git = Git.open(onlineGitFolder);
String tag = JGitUtil.tags(git.getRepository()).get(0);
// when: push latest tag
JGitUtil.push(onlineGitFolder.toPath(), "local", tag);
// then: tag size is 1
Assert.assertEquals(1, Git.open(localGitFolder).tagList().call().size());
// then: tag is v1.1
Assert.assertEquals("v1.1", JGitUtil.tags(localGitFolder.toPath()).get(0));
}
示例3: commitSomething
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
private void commitSomething(Path path) {
try (Git git = Git.open(path.toFile())) {
Path emptyFilePath = Paths.get(path.toString(), EMPTY_FILE);
try {
Files.createFile(emptyFilePath);
} catch (FileAlreadyExistsException ignore) {
}
git.add()
.addFilepattern(".")
.call();
git.commit()
.setMessage("add test branch")
.call();
} catch (Throwable e) {
LOGGER.error("Method: commitSomething Exception", e);
}
}
示例4: open
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
Git open(File file) {
try {
return Git.open(file);
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例5: getRepo
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public static Repository getRepo(Path path) throws GitException {
try (Git git = Git.open(path.toFile())) {
return git.getRepository();
} catch (IOException e) {
throw new GitException(e.getMessage());
}
}
示例6: tags
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public static List<String> tags(Path gitPath) throws GitException {
try (Git git = Git.open(gitPath.toFile())) {
try (Repository repo = git.getRepository()) {
return tags(repo);
}
} catch (IOException e) {
throw new GitException(e.getMessage());
}
}
示例7: push
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
/**
* Push code to remote repo
*
* @param path
* @param remote
* @param branchOrTag
* @return
* @throws GitException
*/
public static Path push(Path path, String remote, String branchOrTag) throws GitException {
try (Git git = Git.open(path.toFile())) {
git.push()
.setRemote(remote)
.setRefSpecs(new RefSpec(branchOrTag))
.call();
} catch (Throwable throwable) {
throw new GitException("Fail to Push ", throwable);
}
return path;
}
示例8: tryToOpenExistingRepoAndCheckRemote
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
private static Git tryToOpenExistingRepoAndCheckRemote( final File repoFolder, final String expectedRepoUrl ) {
try {
final Git repo = Git.open( repoFolder );
if ( originIsRepoUrl( repo, expectedRepoUrl ) ) {
return repo;
} else {
log.error( "Repo has wrong remote URL!" );
return null;
}
} catch ( final Exception e ) {
log.error( "Exception while open repo!", e );
return null;
}
}
示例9: fetchTags
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
/**
* fetch tags from remote
* @param path
* @param remoteName
* @return
* @throws GitException
*/
public static Path fetchTags(Path path, String remoteName) throws GitException {
try (Git git = Git.open(path.toFile())) {
git.fetch()
.setRemote(remoteName)
.setRefSpecs(new RefSpec("refs/tags/*:refs/tags/*"))
.setTagOpt(TagOpt.FETCH_TAGS)
.call();
} catch (Throwable throwable) {
throw new GitException("fetch tags error", throwable);
}
return path;
}
示例10: checkout
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public static Path checkout(Path path, String branch) throws GitException {
try (Git git = Git.open(path.toFile())) {
git
.checkout()
.setName(branch)
.call();
} catch (Throwable throwable) {
throw new GitException("fetch tags error", throwable);
}
return path;
}
示例11: listCommits
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
/**
* List branch commits
* @param path
* @return
* @throws GitException
*/
public static List<RevCommit> listCommits(Path path) throws GitException {
try (Git git = Git.open(path.toFile())) {
Iterable<RevCommit> iterable = git.log().call();
List<RevCommit> commits = stream(iterable.spliterator(), false).collect(toList());
return commits;
} catch (Throwable throwable) {
throw new GitException("get commits error", throwable);
}
}
示例12: gitOpen
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
private Git gitOpen() throws GitException {
try {
return Git.open(getGitPath().toFile());
} catch (IOException e) {
throw new GitException("Fail to open .git folder", e);
}
}
示例13: init
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
@Override
public void init(MavenSession session, Logger logger) throws RevisionGeneratorException {
Git git = null;
try {
if (session.getExecutionRootDirectory() == null) {
revision = "1.0-SNAPSHOT";
dirty = true;
} else {
File gitDir = new FileRepositoryBuilder()
.findGitDir(new File(session.getExecutionRootDirectory()))
.getGitDir();
if (gitDir != null && gitDir.exists()) {
git = Git.open(gitDir);
init(git, logger);
} else {
revision = "1.0-SNAPSHOT";
dirty = true;
}
}
} catch (IOException ex) {
throw new RevisionGeneratorException("Issue opening Git repository for the project", ex);
} finally {
if (git != null) {
git.close();
}
}
}
示例14: should_fetch_tags_success
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
@Test
public void should_fetch_tags_success() throws Throwable {
File localGitFolder = folder.newFolder("info.git");
File onlineGitFolder = folder.newFolder("info");
JGitUtil.init(onlineGitFolder.toPath(), false);
JGitUtil.init(localGitFolder.toPath(), true);
JGitUtil.remoteSet(onlineGitFolder.toPath(), "origin", GIT_URL);
JGitUtil.remoteSet(onlineGitFolder.toPath(), "local", localGitFolder.toString());
JGitUtil.fetchTags(onlineGitFolder.toPath(), GIT_URL);
Git git = Git.open(onlineGitFolder);
Assert.assertEquals(2, git.remoteList().call().size());
Assert.assertEquals(false, JGitUtil.tags(git.getRepository()).isEmpty());
}
示例15: commitRepo
import org.eclipse.jgit.api.Git; //导入方法依赖的package包/类
public void commitRepo() {
try {
Git git = Git.open(worldsDir);
new CustomAddCommand(git.getRepository()).addFilepattern(".").call();
git.commit().setAuthor("voxelgameslib", "[email protected]")
.setMessage("Update " + LocalDateTime.now().toString()).call();
// don't push here, thats need to be done manually
} catch (IOException | GitAPIException e) {
e.printStackTrace();
}
}