List of usage examples for org.eclipse.jgit.transport PushResult getTrackingRefUpdates
public Collection<TrackingRefUpdate> getTrackingRefUpdates()
From source file:com.rimerosolutions.ant.git.tasks.PushTask.java
License:Apache License
@Override protected void doExecute() { try {//from w w w . ja v a 2 s . com StoredConfig config = git.getRepository().getConfig(); List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(config); if (remoteConfigs.isEmpty()) { URIish uri = new URIish(getUri()); RemoteConfig remoteConfig = new RemoteConfig(config, Constants.DEFAULT_REMOTE_NAME); remoteConfig.addURI(uri); remoteConfig.addFetchRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.addPushRefSpec(new RefSpec(DEFAULT_REFSPEC_STRING)); remoteConfig.update(config); config.save(); } String currentBranch = git.getRepository().getBranch(); List<RefSpec> specs = Arrays.asList(new RefSpec(currentBranch + ":" + currentBranch)); if (deleteRemoteBranch != null) { specs = Arrays.asList(new RefSpec(":" + Constants.R_HEADS + deleteRemoteBranch)); } PushCommand pushCommand = git.push().setPushAll().setRefSpecs(specs).setDryRun(false); if (getUri() != null) { pushCommand.setRemote(getUri()); } setupCredentials(pushCommand); if (includeTags) { pushCommand.setPushTags(); } if (getProgressMonitor() != null) { pushCommand.setProgressMonitor(getProgressMonitor()); } Iterable<PushResult> pushResults = pushCommand.setForce(true).call(); for (PushResult pushResult : pushResults) { log(pushResult.getMessages()); GitTaskUtils.validateRemoteRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getRemoteUpdates()); GitTaskUtils.validateTrackingRefUpdates(PUSH_FAILED_MESSAGE, pushResult.getTrackingRefUpdates()); } } catch (Exception e) { if (pushFailedProperty != null) { getProject().setProperty(pushFailedProperty, e.getMessage()); } throw new GitBuildException(PUSH_FAILED_MESSAGE, e); } }
From source file:org.eclipse.egit.gitflow.op.CurrentBranchPublishOperationTest.java
License:Open Source License
@Test public void testFeaturePublish() throws Exception { new InitOperation(repository2.getRepository()).execute(null); GitFlowRepository gfRepo2 = new GitFlowRepository(repository2.getRepository()); new FeatureStartOperation(gfRepo2, MY_FEATURE).execute(null); RevCommit branchCommit = repository2.createInitialCommit("testFeaturePublish"); CurrentBranchPublishOperation featurePublishOperation = new CurrentBranchPublishOperation(gfRepo2, 0); featurePublishOperation.execute(null); PushOperationResult result = featurePublishOperation.getOperationResult(); assertTrue(result.isSuccessfulConnection(repository1.getUri())); PushResult pushResult = result.getPushResult(repository1.getUri()); assertEquals(RefUpdate.Result.NEW, pushResult.getTrackingRefUpdates().iterator().next().getResult()); assertCommitArrivedAtRemote(branchCommit, repository1.getRepository()); // config updated? assertEquals(DEFAULT_REMOTE_NAME, getRemoteName(gfRepo2, MY_FEATURE)); assertEquals(R_HEADS + gfRepo2.getConfig().getFeatureBranchName(MY_FEATURE), gfRepo2.getUpstreamBranchName(MY_FEATURE)); }
From source file:org.exist.git.xquery.Push.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {// w ww. jav a2s.c o m 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); } }