List of usage examples for org.eclipse.jgit.lib ObjectId abbreviate
public AbbreviatedObjectId abbreviate(int len)
From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java
License:Apache License
protected long getLongId(ObjectId objectId) { String h = objectId.abbreviate(ABBREVIATED_ID_LENGTH).name(); return Long.parseLong(h, 16); }
From source file:com.github.gitreport.ReleaseReport.java
License:Open Source License
/** * Get abbreviated name for id//from w w w. ja va2s . co m * * @param id * @return short name */ public String getCommitShortName(ObjectId id) { if (linker != null) { String url = linker.getCommitUrl(id.name()); if (url != null) { return "<a href=\"" + url + "\">" + id.abbreviate(7).name() + "</a>"; } } return id.abbreviate(7).name(); }
From source file:com.github.kevinsawicki.git.reports.ReleaseReport.java
License:Open Source License
/** * Get abbreviated name for id//from w w w.j a v a 2 s . c o m * * @param id * @return short name */ public String getCommitShortName(ObjectId id) { if (linker != null) { String url = linker.getCommitUrl(id.name()); if (url != null) return "<a href=\"" + url + "\">" + id.abbreviate(7).name() + "</a>"; } return id.abbreviate(7).name(); }
From source file:com.google.gerrit.acceptance.git.ImplicitMergeCheckIT.java
License:Apache License
private static String implicitMergeOf(ObjectId commit) { return "implicit merge of " + commit.abbreviate(7).name(); }
From source file:com.madgag.agit.views.ObjectIdView.java
License:Open Source License
public void setObjectId(final ObjectId objectId) { setText(objectId.abbreviate(8).name()); setOnClickListener(new OnClickListener() { public void onClick(View v) { String idText = objectId.name(); clipboardManager.setText(idText); String htmlMessage = "<small><small><b><tt>" + objectId.name() + "</tt></b></small><br />(copied to clipboard!)</small>"; Toast.makeText(getContext(), centered(htmlMessage), LENGTH_SHORT).show(); }/*from w w w .j a v a 2 s. com*/ }); }
From source file:com.mooregreatsoftware.gitprocess.lib.Branch.java
License:Apache License
public boolean contains(@NonNull ObjectId oid) { LOG.debug("{}.contains({})", this, oid.abbreviate(7).name()); return Try.of(() -> { final RevWalk walk = new RevWalk(gitLib.repository()); try {/*from w w w. j a v a 2 s.c o m*/ walk.setRetainBody(false); final RevCommit topOfThisBranch = walk.parseCommit(objectId()); walk.markStart(topOfThisBranch); return StreamSupport.stream(walk.spliterator(), false) .anyMatch(commit -> oid.equals(commit.getId())); } finally { walk.dispose(); } }).getOrElseThrow((Function<Throwable, IllegalStateException>) IllegalStateException::new); }
From source file:com.mooregreatsoftware.gitprocess.lib.Merger.java
License:Apache License
public static Either<String, SuccessfulMerge> merge(GitLib gitLib, Branch mergeBranch) { final Branch currentBranch = gitLib.branches().currentBranch(); if (currentBranch == null) return left("There is no branch checked out"); final ObjectId startCurrentOid = currentBranch.objectId(); final ObjectId startIntegrationOid = mergeBranch.objectId(); LOG.debug("Merging \"{}\"({}) with \"{}\"({})", currentBranch.shortName(), startCurrentOid.abbreviate(7).name(), mergeBranch.shortName(), startIntegrationOid.abbreviate(7).name()); final MergeResult mergeResult = (@NonNull MergeResult) e( () -> gitLib.jgit().merge().include(mergeBranch.objectId()).setCommit(true) .setMessage("Sync merge from " + mergeBranch.shortName() + " into " + (currentBranch != null ? currentBranch.shortName() : null)) .call());// w w w . j a v a 2 s .c o m return mergeResult.getMergeStatus().isSuccessful() ? right(new SuccessfulMerge(mergeResult)) : left(mergeResult.getMergeStatus().toString()); }
From source file:com.mooregreatsoftware.gitprocess.process.Sync.java
License:Apache License
/** * @return Left(error message), Right(the Pusher to use) *//*ww w.jav a2s . c o m*/ @SuppressWarnings("PointlessBooleanExpression") private static <T> Either<String, Pusher> handleRemoteChanged(GitLib gitLib, Branch currentBranch, Combiner<T> combiner) { LOG.debug("Handle potential remote changed"); final ObjectId remoteOID = currentBranch.remoteOID(); final Either<String, @Nullable ObjectId> eLastSynced = currentBranch.lastSyncedAgainst(); if (eLastSynced.isLeft()) return left(eLastSynced.getLeft()); final ObjectId lastSyncedOID = eLastSynced.get(); if (lastSyncedOID != null) { // deal with possible change if (remoteOID == null) { LOG.warn("The remote version of this branch has disappeared"); return right(Pusher.create(gitLib, currentBranch, currentBranch.simpleName())); } if (remoteOID.equals(lastSyncedOID)) { LOG.debug("The last synced OID is the same as the remote OID: {}", remoteOID.abbreviate(7).name()); if (currentBranch.contains(remoteOID)) { LOG.debug("\"{}\" contains {} so will do a normal fast-forward push", currentBranch.simpleName(), remoteOID.abbreviate(7).name()); return right(Pusher.create(gitLib, currentBranch, currentBranch.simpleName())); } else { LOG.debug( "{} does not appear in the history of \"{}\", but since it was not remotely " + "changed going to assume that the local copy is correct and will force push", remoteOID.abbreviate(7).name(), currentBranch.simpleName()); return right( Pusher.create(gitLib, currentBranch, currentBranch.simpleName(), true, null, null)); } } else { LOG.warn( "The remote branch has changed since the last time this was " + "synced ({} -> {}) so attempting to reconcile", lastSyncedOID.abbreviate(7).name(), remoteOID.abbreviate(7).name()); // reconcile against the remote branch return reconcileWithRemoteBranch(gitLib, currentBranch, combiner); } } else { LOG.debug("This has not been synced before"); if (remoteOID == null) { return right(Pusher.create(gitLib, currentBranch, currentBranch.simpleName())); } if (currentBranch.contains(remoteOID)) { LOG.debug("\"{}\" contains {} so will do a normal fast-forward push", currentBranch.simpleName(), remoteOID.abbreviate(7).name()); return right(Pusher.create(gitLib, currentBranch, currentBranch.simpleName())); } else { LOG.warn("The remote branch has changed since this branch was " + "created (i.e., it does not contain the remote revision {}) so attempting to reconcile", remoteOID.abbreviate(7).name()); // reconcile against the remote branch return reconcileWithRemoteBranch(gitLib, currentBranch, combiner); } } }
From source file:com.rimerosolutions.ant.git.tasks.CurrentBranchTask.java
License:Apache License
@Override protected void doExecute() { try {//from w w w . ja v a 2 s . co m Repository repository = git.getRepository(); String branch = repository.getBranch(); // Backward compatibility getProject().setProperty(outputProperty, branch); ObjectId objectId = repository.getRef(Constants.HEAD).getObjectId(); // Extended (nested) properties if (objectId != null) { getProject().setProperty(outputProperty + ".name", branch); getProject().setProperty(outputProperty + ".id", objectId.name()); getProject().setProperty(outputProperty + ".shortId", objectId.abbreviate(8).name()); } } catch (IOException e) { throw new GitBuildException("Could not query the current branch.", e); } }
From source file:fr.brouillard.oss.jgitver.strategy.maven.defaults.Scenario12WithDefaultsTest.java
License:Apache License
@Test public void version_of_master() { // checkout the commit in scenario unchecked(() -> git.checkout().setName("master").call()); assertThat(versionCalculator.getVersion(), is("1.0.0")); assertThat(versionCalculator.meta(Metadatas.BRANCH_NAME).get(), is("master")); assertThat(versionCalculator.meta(Metadatas.BASE_TAG).get(), is("1.0.0")); assertThat(versionCalculator.meta(Metadatas.DIRTY).get(), is("false")); // TODO open a defect in jgit, order of tags is not respected between v1.0.0 & 1.0.0 // assertThat(versionCalculator.meta(Metadatas.ALL_TAGS).get(), is("v2.0.0,1.0.0,1.0.0-rc02,1.0.0-rc01,v1.0.0")); // assertThat(versionCalculator.meta(Metadatas.ALL_ANNOTATED_TAGS).get(), is("1.0.0,1.0.0-rc02,1.0.0-rc01")); assertThat(versionCalculator.meta(Metadatas.ALL_LIGHTWEIGHT_TAGS).get(), is("v2.0.0,v1.0.0")); // assertThat(versionCalculator.meta(Metadatas.ALL_VERSION_TAGS).get(), is("v2.0.0,1.0.0,1.0.0-rc02,1.0.0-rc01,v1.0.0")); // assertThat(versionCalculator.meta(Metadatas.ALL_VERSION_ANNOTATED_TAGS).get(), is("1.0.0,1.0.0-rc02,1.0.0-rc01")); assertThat(versionCalculator.meta(Metadatas.ALL_VERSION_LIGHTWEIGHT_TAGS).get(), is("v2.0.0,v1.0.0")); assertThat(versionCalculator.meta(Metadatas.HEAD_TAGS).get(), is("v2.0.0,1.0.0")); assertThat(versionCalculator.meta(Metadatas.HEAD_ANNOTATED_TAGS).get(), is("1.0.0")); assertThat(versionCalculator.meta(Metadatas.HEAD_LIGHTWEIGHT_TAGS).get(), is("v2.0.0")); ObjectId headCommit = scenario.getCommits().get("G"); assertThat(versionCalculator.meta(Metadatas.GIT_SHA1_FULL).get(), is(headCommit.name())); assertThat(versionCalculator.meta(Metadatas.GIT_SHA1_8).get(), is(headCommit.abbreviate(8).name())); }