List of usage examples for org.eclipse.jgit.api DescribeCommand call
@Override public String call() throws GitAPIException
Describes the specified commit.
From source file:com.dell.doradus.core.DoradusServer.java
License:Apache License
/** * Get Doradus Version from git repo if it exists; otherwise get it from the local doradus.ver file * @return version/*from ww w . j a va2 s . co m*/ */ public static String getDoradusVersion() { String version = null; try { //first read from the local git repository Git git = Git.open(new File("../.git")); String url = git.getRepository().getConfig().getString("remote", "origin", "url"); instance().m_logger.info("Remote.origin.url: {}", url); if (!Utils.isEmpty(url) && url.contains("dell-oss/Doradus.git")) { DescribeCommand cmd = git.describe(); version = cmd.call(); instance().m_logger.info("Doradus version found from git repo: {}", version); writeVersionToVerFile(version); } } catch (Throwable e) { instance().m_logger.info("failed to read version from git repo"); } //if not found, reading from local file if (Utils.isEmpty(version)) { try { version = getVersionFromVerFile(); instance().m_logger.info("Doradus version found from doradus.ver file {}", version); } catch (IOException e1) { version = null; } } return version; }
From source file:org.eclipse.emf.compare.doc.WikiTextToHTML.java
License:Open Source License
private String gitDescribe() { FileRepositoryBuilder builder = new FileRepositoryBuilder(); try {// w w w .j a v a 2 s . c o m Repository repo = builder.setWorkTree(new File(".")).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); Git git = new Git(repo); DescribeCommand command = git.describe(); return command.call(); } catch (IOException e) { new RuntimeException(e); } catch (GitAPIException e) { new RuntimeException(e); } return ""; }
From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java
License:Open Source License
@Test public void shouldGiveTheCommitIdWhenNothingElseCanBeFound() throws Exception { // given// w w w . j a v a 2 s.com mavenSandbox.withParentProject(PROJECT_NAME, "jar").withNoChildProject() .withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT) .create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST); Repository repo = git().getRepository(); // when DescribeCommand command = spy(DescribeCommand.on(repo)); doReturn(false).when(command).findDirtyState(any(Repository.class)); command.setVerbose(true); DescribeResult res = command.call(); // then assertThat(res).isNotNull(); RevCommit HEAD = git().log().call().iterator().next(); assertThat(res.toString()).isEqualTo(abbrev(HEAD.getName())); }
From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java
License:Open Source License
@Test public void shouldGiveTheCommitIdWhenTagIsOnOtherBranch() throws Exception { // given/*from w ww.j av a 2 s.c om*/ mavenSandbox.withParentProject(PROJECT_NAME, "jar").withNoChildProject() .withGitRepoInParent(AvailableGitTestRepo.WITH_TAG_ON_DIFFERENT_BRANCH) .create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST); Repository repo = git().getRepository(); // when DescribeCommand command = spy(DescribeCommand.on(repo)); doReturn(false).when(command).findDirtyState(any(Repository.class)); command.setVerbose(true); DescribeResult res = command.call(); // then assertThat(res).isNotNull(); RevCommit HEAD = git().log().call().iterator().next(); assertThat(res.toString()).isEqualTo(abbrev(HEAD.getName())); }
From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java
License:Open Source License
@Test public void shouldGiveTheCommitIdWhenNothingElseCanBeFoundAndUseAbbrevVersionOfIt() throws Exception { // given//from w w w .j ava2 s . c o m mavenSandbox.withParentProject(PROJECT_NAME, "jar").withNoChildProject() .withGitRepoInParent(AvailableGitTestRepo.WITH_ONE_COMMIT) .create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST); int abbrevLength = 10; Repository repo = git().getRepository(); // when DescribeCommand command = spy(DescribeCommand.on(repo)); doReturn(false).when(command).findDirtyState(any(Repository.class)); command.setVerbose(true).abbrev(abbrevLength); DescribeResult res = command.call(); // then assertThat(res).isNotNull(); RevCommit HEAD = git().log().call().iterator().next(); assertThat(res.toString()).isEqualTo(abbrev(HEAD.getName(), abbrevLength)); }
From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java
License:Open Source License
@Test public void shouldGiveTagWithDistanceToCurrentCommitAndItsIdAndDirtyMarker() throws Exception { // given//from w w w . j a v a2 s .c om mavenSandbox.withParentProject(PROJECT_NAME, "jar").withNoChildProject() .withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID) .create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST); Repository repo = git().getRepository(); // when DescribeCommand command = DescribeCommand.on(repo); command.dirty(DIRTY_SUFFIX); command.setVerbose(true); DescribeResult res = command.call(); // then assertThat(res).isNotNull(); RevCommit HEAD = git().log().call().iterator().next(); assertThat(res.toString()).isEqualTo("v2.0.4-25-g" + abbrev(HEAD.getName()) + DIRTY_SUFFIX); }
From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java
License:Open Source License
@Test public void shouldGiveTagWithDistanceToCurrentCommitAndItsIdAndCustomDirtyMarker() throws Exception { // given/*from w w w. ja v a2 s . co m*/ mavenSandbox.withParentProject(PROJECT_NAME, "jar").withNoChildProject() .withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID) .create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST); String customDirtySuffix = "-DEV"; Repository repo = git().getRepository(); // when DescribeCommand command = DescribeCommand.on(repo).dirty(customDirtySuffix).setVerbose(true); DescribeResult res = command.call(); // then assertThat(res).isNotNull(); RevCommit HEAD = git().log().call().iterator().next(); assertThat(res.toString()).isEqualTo("v2.0.4-25-g" + abbrev(HEAD.getName()) + customDirtySuffix); }
From source file:pl.project13.jgit.DescribeCommandIntegrationTest.java
License:Open Source License
@Test public void shouldGiveTagWithDistanceToCurrentCommitAndItsId() throws Exception { // given// w w w . j a v a 2s .co m mavenSandbox.withParentProject(PROJECT_NAME, "jar").withNoChildProject() .withGitRepoInParent(AvailableGitTestRepo.GIT_COMMIT_ID) .create(FileSystemMavenSandbox.CleanUp.CLEANUP_FIRST); Repository repo = git().getRepository(); Git.wrap(repo).reset().setMode(ResetCommand.ResetType.HARD).call(); // when DescribeCommand command = DescribeCommand.on(repo); command.setVerbose(true); DescribeResult res = command.call(); // then assertThat(res).isNotNull(); RevCommit HEAD = git().log().call().iterator().next(); assertThat(res.toString()).isEqualTo("v2.0.4-25-g" + abbrev(HEAD.getName())); }