List of usage examples for org.eclipse.jgit.transport RemoteRefUpdate RemoteRefUpdate
public RemoteRefUpdate(final Repository localDb, final Ref srcRef, final String remoteName, final boolean forceUpdate, final String localName, final ObjectId expectedOldObjectId) throws IOException
From source file:com.gmail.cjbooms.thesis.pythonappengine.server.git.GitCommandsServiceImpl.java
License:Open Source License
/** * Push Changes to a Remote Repository//from ww w . j av a2 s . co m * * @param pathToLocalRepository Root Location Of Repository or Project * @param remoteRepoURL The URL of the Remote Repository to push to * @param userName The remote login user name * @param password The remote login password * @throws IOException, GitAPIException, URISyntaxException */ public void pushLocalCommitsToRemoteRepository(String pathToLocalRepository, String remoteRepoURL, String userName, String password) throws IOException { File repositoryDirectory = new File(pathToLocalRepository); Git localGitRepositoryRef = Git.open(repositoryDirectory); Repository localRepository = localGitRepositoryRef.getRepository(); URIish remoteURI = null; try { remoteURI = new URIish(remoteRepoURL); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage()); } Transport t = Transport.open(localRepository, remoteURI); ((TransportHttp) t).setUseSmartHttp(true); RemoteRefUpdate remoteRefUpdate = new RemoteRefUpdate(localRepository, localRepository.getRef("master"), "refs/heads/master", true, "refs/heads/master", null); t.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password)); t.push(NullProgressMonitor.INSTANCE, Collections.singleton(remoteRefUpdate)); }
From source file:com.google.gerrit.server.git.PushOp.java
License:Apache License
private void send(final List<RemoteRefUpdate> cmds, final RefSpec spec, final Ref src) throws IOException { final String dst = spec.getDestination(); final boolean force = spec.isForceUpdate(); cmds.add(new RemoteRefUpdate(db, src, dst, force, null, null)); }
From source file:com.google.gerrit.server.git.PushOp.java
License:Apache License
private void delete(final List<RemoteRefUpdate> cmds, final RefSpec spec) throws IOException { final String dst = spec.getDestination(); final boolean force = spec.isForceUpdate(); cmds.add(new RemoteRefUpdate(db, (Ref) null, dst, force, null, null)); }
From source file:com.googlesource.gerrit.plugins.replication.PushOne.java
License:Apache License
private void push(List<RemoteRefUpdate> cmds, RefSpec spec, Ref src) throws IOException { String dst = spec.getDestination(); boolean force = spec.isForceUpdate(); cmds.add(new RemoteRefUpdate(git, src, dst, force, null, null)); }
From source file:com.googlesource.gerrit.plugins.replication.PushOne.java
License:Apache License
private void delete(List<RemoteRefUpdate> cmds, RefSpec spec) throws IOException { String dst = spec.getDestination(); boolean force = spec.isForceUpdate(); cmds.add(new RemoteRefUpdate(git, (Ref) null, dst, force, null, null)); }
From source file:org.eclipse.egit.core.test.op.PushOperationTest.java
License:Open Source License
/** * We should get an {@link IllegalStateException} if the spec was re-used * * @throws Exception/*from ww w . ja v a 2 s .co m*/ */ @Test public void testPushWithReusedSpec() throws Exception { PushOperationSpecification spec = new PushOperationSpecification(); // the remote is repo2 URIish remote = new URIish("file:///" + repository2.getRepository().getDirectory().toString()); // update master upon master List<RemoteRefUpdate> refUpdates = new ArrayList<RemoteRefUpdate>(); RemoteRefUpdate update = new RemoteRefUpdate(repository1.getRepository(), "HEAD", "refs/heads/test", false, null, null); refUpdates.add(update); spec.addURIRefUpdates(remote, refUpdates); PushOperation pop = new PushOperation(repository1.getRepository(), spec, false, null, 0); pop.run(null); pop = new PushOperation(repository1.getRepository(), spec, false, null, 0); try { pop.run(null); fail("Expected Exception not thrown"); } catch (IllegalStateException e) { // expected } }
From source file:org.eclipse.egit.core.test.op.PushOperationTest.java
License:Open Source License
private PushOperation createPushOperation() throws Exception { // set up push from repository1 to repository2 // we can not re-use the RemoteRefUpdate!!! PushOperationSpecification spec = new PushOperationSpecification(); // the remote is repo2 URIish remote = new URIish("file:///" + repository2.getRepository().getDirectory().toString()); // update master upon master List<RemoteRefUpdate> refUpdates = new ArrayList<RemoteRefUpdate>(); RemoteRefUpdate update = new RemoteRefUpdate(repository1.getRepository(), "HEAD", "refs/heads/test", false, null, null);/* w ww . j a va 2 s . c om*/ refUpdates.add(update); spec.addURIRefUpdates(remote, refUpdates); // now we can construct the push operation PushOperation pop = new PushOperation(repository1.getRepository(), spec, false, null, 0); return pop; }
From source file:org.eclipse.egit.ui.internal.push.PushToGerritPage.java
License:Open Source License
void doPush(IProgressMonitor monitor) { try {/*from w w w .jav a2s . c om*/ int timeout = Activator.getDefault().getPreferenceStore() .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); URIish uri = new URIish(uriCombo.getText()); Ref currentHead = repository.getRef(Constants.HEAD); RemoteRefUpdate update = new RemoteRefUpdate(repository, currentHead, prefixCombo.getItem(prefixCombo.getSelectionIndex()) + branchText.getText(), false, null, null); PushOperationSpecification spec = new PushOperationSpecification(); spec.addURIRefUpdates(uri, Arrays.asList(update)); PushOperationUI op = new PushOperationUI(repository, spec, timeout, false); op.setCredentialsProvider(new EGitCredentialsProvider()); PushOperationResult result = op.execute(monitor); PushResultDialog dlg = new PushResultDialog(getShell(), repository, result, op.getDestinationString()); dlg.showConfigureButton(false); dlg.open(); storeLastUsedUri(uriCombo.getText()); storeLastUsedBranch(branchText.getText()); } catch (CoreException e) { Activator.handleError(e.getMessage(), e, true); } catch (URISyntaxException e) { Activator.handleError(e.getMessage(), e, true); } catch (IOException e) { Activator.handleError(e.getMessage(), e, true); } }
From source file:org.kuali.student.git.importer.JGitPushMain.java
License:Educational Community License
/** * @param args//from ww w. j av a2s .c o m */ public static void main(String[] args) { if (args.length != 4 && args.length != 5) { System.err.println("USAGE: <git repository> <bare> <remote name> <branch prefixes> [<ref prefix>]"); System.err.println( "\t<branch prefixes> : like enrollment_ks-enroll (colon seperated for multiple prefixes)"); System.err.println( "\t<ref prefix> : like refs/heads/ or refs/remotes/origin/ needs to end with a trailing slash /"); System.exit(-1); } boolean bare = false; if (args[1].trim().equals("true")) { bare = true; } String remoteName = args[2]; String branchPrefixes[] = args[3].split(":"); String refPrefix = Constants.R_HEADS; if (args.length == 5) refPrefix = args[4].trim(); try { Repository repo = GitRepositoryUtils.buildFileRepository(new File(args[0]).getAbsoluteFile(), false, bare); Collection<Ref> refsToPush = repo.getRefDatabase().getRefs(refPrefix).values(); List<RemoteRefUpdate> refsToUpdate = new ArrayList<>(); for (String branchPrefix : branchPrefixes) { String adjustedBranchPrefix = refPrefix + branchPrefix; for (Ref candidateRef : refsToPush) { if (candidateRef.getName().startsWith(adjustedBranchPrefix)) { String candidateBranchName = candidateRef.getName().substring(refPrefix.length()); String targetRefName = Constants.R_HEADS + candidateBranchName; log.info("pushing " + adjustedBranchPrefix + " to " + targetRefName); refsToUpdate.add(new RemoteRefUpdate(repo, candidateRef, targetRefName, true, null, null)); } } } RevWalk rw = new RevWalk(repo); push(repo, remoteName, refsToUpdate, null, null); rw.release(); repo.close(); } catch (Exception e) { log.error("unexpected Exception ", e); } }