List of usage examples for org.eclipse.jgit.transport RemoteRefUpdate getNewObjectId
public ObjectId getNewObjectId()
From source file:com.gitblit.tests.TicketReferenceTest.java
License:Apache License
@BeforeClass public static void configure() throws Exception { File repositoryName = new File("TicketReferenceTest.git"); ;/* w ww .j av a 2 s . co m*/ GitBlitSuite.close(repositoryName); if (repositoryName.exists()) { FileUtils.delete(repositoryName, FileUtils.RECURSIVE | FileUtils.RETRY); } repo = new RepositoryModel("TicketReferenceTest.git", null, null, null); if (gitblit().hasRepository(repo.name)) { gitblit().deleteRepositoryModel(repo); } gitblit().updateRepositoryModel(repo.name, repo, true); user = new UserModel(account); user.displayName = account; user.emailAddress = account + "@example.com"; user.password = password; cp = new UsernamePasswordCredentialsProvider(user.username, user.password); if (gitblit().getUserModel(user.username) != null) { gitblit().deleteUser(user.username); } repo.authorizationControl = AuthorizationControl.NAMED; repo.accessRestriction = AccessRestrictionType.PUSH; gitblit().updateRepositoryModel(repo.name, repo, false); // grant user push permission user.setRepositoryPermission(repo.name, AccessPermission.REWIND); gitblit().updateUserModel(user); ticketService = gitblit().getTicketService(); assertTrue(ticketService.deleteAll(repo)); GitBlitSuite.close(workingCopy); if (workingCopy.exists()) { FileUtils.delete(workingCopy, FileUtils.RECURSIVE | FileUtils.RETRY); } CloneCommand clone = Git.cloneRepository(); clone.setURI(MessageFormat.format("{0}/{1}", url, repo.name)); clone.setDirectory(workingCopy); clone.setBare(false); clone.setBranch("master"); clone.setCredentialsProvider(cp); GitBlitSuite.close(clone.call()); git = Git.open(workingCopy); git.getRepository().getConfig().setString("user", null, "name", user.displayName); git.getRepository().getConfig().setString("user", null, "email", user.emailAddress); git.getRepository().getConfig().save(); final RevCommit revCommit1 = makeCommit("initial commit"); final String initialSha = revCommit1.name(); Iterable<PushResult> results = git.push().setPushAll().setCredentialsProvider(cp).call(); GitBlitSuite.close(git); for (PushResult result : results) { for (RemoteRefUpdate update : result.getRemoteUpdates()) { assertEquals(Status.OK, update.getStatus()); assertEquals(initialSha, update.getNewObjectId().name()); } } }
From source file:com.gitblit.tests.TicketReferenceTest.java
License:Apache License
private void assertPushSuccess(String commitSha, String branchName) throws Exception { Iterable<PushResult> results = git.push().setRemote("origin").setCredentialsProvider(cp).call(); for (PushResult result : results) { RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/" + branchName); assertEquals(Status.OK, ref.getStatus()); assertEquals(commitSha, ref.getNewObjectId().name()); }/*from w w w . j ava 2 s .c o m*/ }
From source file:com.gitblit.tests.TicketReferenceTest.java
License:Apache License
private void assertForcePushSuccess(String commitSha, String branchName) throws Exception { Iterable<PushResult> results = git.push().setForce(true).setRemote("origin").setCredentialsProvider(cp) .call();/*from ww w . j a va 2 s. c om*/ for (PushResult result : results) { RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/" + branchName); assertEquals(Status.OK, ref.getStatus()); assertEquals(commitSha, ref.getNewObjectId().name()); } }
From source file:io.fabric8.collector.git.GitHelpers.java
License:Apache License
public static String toString(Collection<RemoteRefUpdate> updates) { StringBuilder builder = new StringBuilder(); for (RemoteRefUpdate update : updates) { if (builder.length() > 0) { builder.append(" "); }// w w w.j av a 2s . co m builder.append(update.getMessage() + " " + update.getRemoteName() + " " + update.getNewObjectId()); } return builder.toString(); }
From source file:io.fabric8.forge.rest.git.RepositoryResource.java
License:Apache License
protected String toString(Collection<RemoteRefUpdate> updates) { StringBuilder builder = new StringBuilder(); for (RemoteRefUpdate update : updates) { if (builder.length() > 0) { builder.append(" "); }//from ww w .j a va 2 s . co m builder.append(update.getMessage() + " " + update.getRemoteName() + " " + update.getNewObjectId()); } return builder.toString(); }
From source file:jbyoshi.gitupdate.processor.Push.java
License:Apache License
private static void process(Repository repo, Git git, String remote, Collection<String> branches, Report report) throws Exception { // Figure out if anything needs to be pushed. Map<String, ObjectId> oldIds = new HashMap<>(); boolean canPush = false; for (String branch : branches) { BranchConfig config = new BranchConfig(repo.getConfig(), branch); ObjectId target = repo.getRef(branch).getObjectId(); Ref remoteRef = repo.getRef(config.getRemoteTrackingBranch()); if (remoteRef == null || !target.equals(remoteRef.getObjectId())) { canPush = true;// w ww . j a v a 2 s . c om } oldIds.put(branch, remoteRef == null ? ObjectId.zeroId() : remoteRef.getObjectId()); } if (!canPush) { return; } PushCommand push = git.push().setCredentialsProvider(Prompts.INSTANCE).setTimeout(5).setRemote(remote); for (String branch : branches) { push.add(Constants.R_HEADS + branch); } for (PushResult result : push.call()) { for (RemoteRefUpdate update : result.getRemoteUpdates()) { if (update.getStatus() == RemoteRefUpdate.Status.OK) { String branchName = Utils.getShortBranch(update.getSrcRef()); ObjectId oldId = oldIds.get(branchName); String old = oldId.equals(ObjectId.zeroId()) ? "new branch" : oldId.name(); report.newChild(branchName + ": " + old + " -> " + update.getNewObjectId().name()).modified(); } } } }
From source file:org.eclipse.egit.core.op.PushOperationResult.java
License:Open Source License
/** * This implementation returns true if all following conditions are met: * <ul>// w w w. ja va 2 s . c o m * <li>both objects result have the same set successfully connected * repositories (URIs) - unsuccessful connections are discarded, AND <li> * remote ref updates must match for each successful connection in sense of * equal remoteName, equal status and equal newObjectId value.</li> * </ul> * * @see Object#equals(Object) * @param obj * other push operation result to compare to. * @return true if object is equal to this one in terms of conditions * described above, false otherwise. */ @Override public boolean equals(final Object obj) { if (obj == this) return true; if (!(obj instanceof PushOperationResult)) return false; final PushOperationResult other = (PushOperationResult) obj; // Check successful connections/URIs two-ways: final Set<URIish> otherURIs = other.getURIs(); for (final URIish uri : getURIs()) { if (isSuccessfulConnection(uri) && (!otherURIs.contains(uri) || !other.isSuccessfulConnection(uri))) return false; } for (final URIish uri : other.getURIs()) { if (other.isSuccessfulConnection(uri) && (!urisEntries.containsKey(uri) || !isSuccessfulConnection(uri))) return false; } for (final URIish uri : getURIs()) { if (!isSuccessfulConnection(uri)) continue; final PushResult otherPushResult = other.getPushResult(uri); for (final RemoteRefUpdate rru : getPushResult(uri).getRemoteUpdates()) { final RemoteRefUpdate otherRru = otherPushResult.getRemoteUpdate(rru.getRemoteName()); if (otherRru == null) return false; if (otherRru.getStatus() != rru.getStatus() || otherRru.getNewObjectId() != rru.getNewObjectId()) return false; } } return true; }
From source file:org.exist.git.xquery.Push.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {//from w w w . j av a 2s . c om String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Git git = Git.open(new Resource(localPath), FS); Iterable<PushResult> answer = git.push().setCredentialsProvider( new UsernamePasswordCredentialsProvider(args[1].getStringValue(), args[2].getStringValue())) .call(); MemTreeBuilder builder = getContext().getDocumentBuilder(); int nodeNr = builder.startElement(PUSH, null); for (PushResult push : answer) { builder.startElement(RESULT, null); for (TrackingRefUpdate tracking : push.getTrackingRefUpdates()) { builder.startElement(TRACKING_REF_UPDATE, null); builder.addAttribute(REMOTE_NAME, tracking.getRemoteName()); builder.addAttribute(LOCAL_NAME, tracking.getLocalName()); //builder.addAttribute(FORCE_UPDATE, Boolean.toString(tracking.forceUpdate)); builder.addAttribute(OLD_OBJECTID, tracking.getOldObjectId().name()); builder.addAttribute(NEW_OBJECTID, tracking.getNewObjectId().name()); } for (RemoteRefUpdate remote : push.getRemoteUpdates()) { builder.startElement(REMOTE_REF_UPDATE, null); builder.addAttribute(REMOTE_NAME, remote.getRemoteName()); builder.addAttribute(STATUS, remote.getStatus().name()); if (remote.isExpectingOldObjectId()) builder.addAttribute(EXPECTED_OLD_OBJECTID, remote.getExpectedOldObjectId().name()); if (remote.getNewObjectId() != null) builder.addAttribute(NEW_OBJECTID, remote.getNewObjectId().name()); builder.addAttribute(FAST_FORWARD, Boolean.toString(remote.isFastForward())); builder.addAttribute(FORCE_UPDATE, Boolean.toString(remote.isForceUpdate())); if (remote.getMessage() != null) builder.characters(remote.getMessage()); builder.endElement(); } builder.endElement(); } builder.endElement(); return builder.getDocument().getNode(nodeNr); } catch (Throwable e) { e.printStackTrace(); throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.jboss.as.server.controller.git.GitConfigurationPersister.java
License:Apache License
@Override public String publish(String name) throws ConfigurationPersistenceException { StringBuilder message = new StringBuilder(); String remoteName = gitRepository.getRemoteName(name); if (remoteName != null && gitRepository.isValidRemoteName(remoteName)) { try (Git git = gitRepository.getGit()) { Iterable<PushResult> result = git.push().setRemote(remoteName) .setRefSpecs(new RefSpec(gitRepository.getBranch() + ':' + gitRepository.getBranch())) .setPushTags().call(); for (PushResult pushResult : result) { for (RemoteRefUpdate refUpdate : pushResult.getRemoteUpdates()) { message.append(refUpdate.getMessage()).append(" ").append(refUpdate.getNewObjectId().name()) .append('\n'); }//w w w . j a v a 2 s . c om } } catch (GitAPIException ex) { throw MGMT_OP_LOGGER.failedToPublishConfiguration(ex, name, ex.getMessage()); } } return message.toString(); }