public void push(boolean tags) throws Exception { PushCommand push = git.push(); if(tags) { push.setPushTags(); } push.call(); }
@Override public Iterable<PushResult> pushPatchBranches() throws GitAPIException { List<Ref> localBranches = mainRepository.branchList().call(); List<RefSpec> toPush = new LinkedList<>(); for (Ref ref : localBranches) { if (ref.getName().startsWith("refs/heads/patches-")) { toPush.add(new RefSpec(ref.getName())); } } return mainRepository.push().setRefSpecs(toPush).setPushTags().call(); }
private void push() throws GitAPIException { Lock writeLock = repositoryLock.writeLock(); try { writeLock.lock(); PushCommand push = git.push().setPushTags().add(branch); if (StringUtils.isNotBlank(login)) { push.setCredentialsProvider(new UsernamePasswordCredentialsProvider(login, password)); } push.call(); monitor.fireOnChange(); } finally { writeLock.unlock(); } }
@Override public Iterable<PushResult> pushPatchBranches() throws GitAPIException { List<Ref> localBranches = mainRepository.branchList().call(); List<RefSpec> toPush = new LinkedList<>(); for (Ref ref : localBranches) { if (ref.getName().startsWith("refs/heads/patches-")) { toPush.add(new RefSpec(ref.getName())); } } return mainRepository.push().setRefSpecs(toPush).setPushTags().call(); }
/** * Push all changes and tags to given remote. * * @param git * instance. * @param remote * to be used. * * @return List of all results of given push. */ public Iterable<PushResult> pushToRepository(Git git, String remote) { try { return git.push() .setRemote(remote) .setPushAll() .setPushTags() .call(); } catch (GitAPIException e) { throw new IllegalStateException(e); } }
public boolean tag(String tagname, String comment) throws Exception { try{ git.fetch().setTagOpt(TagOpt.FETCH_TAGS).call(); } catch(Exception e) { log.debug("Fetch from origin failed.", e); } List<RevTag> tags = git.tagList().call(); if(tags != null && tags.size() > 0) { for(RevTag tag : tags) { if(tag.getTagName().equals(tagname)) { throw new Exception("Tag already exists."); } } } boolean success = git.tag().setMessage(comment).setName(tagname).call() != null; try{ git.push().setPushTags().call(); } catch(Exception e){ log.debug("Failed to push changes.", e); } return success; }
@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'); } } } catch (GitAPIException ex) { throw MGMT_OP_LOGGER.failedToPublishConfiguration(ex, name, ex.getMessage()); } } return message.toString(); }
@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'); } } } catch (GitAPIException ex) { throw MGMT_OP_LOGGER.failedToPublishConfiguration(ex, name, ex.getMessage()); } } return message.toString(); }
/** * Push all changes and tags to given remote. * * @param git * instance. * @param remote * to be used. * @param username * to login. * @param password * to login. * * @return List of all results of given push. */ public Iterable<PushResult> pushToRepository(Git git, String remote, String username, String password) { try { return git.push() .setRemote(remote) .setPushAll() .setPushTags() .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)) .call(); } catch (GitAPIException e) { throw new IllegalStateException(e); } }
@Override public void push(Git git, String branch) throws GitAPIException { git.push() .setRemote("origin") .setRefSpecs(new RefSpec(branch)) .setPushTags() .setForce(true) .call(); // in fabric env we synchronize changes with "local" git repo, which will be then (from fabric-agent) // pushed further to cluster's git repo if (master && mainRepository != null && !branch.startsWith("patch-") && !branch.equals(getMainBranchName())) { // we don't push "patch-*" branches to central repo (we push "patches-*") // getMainBranchName() is used to track current container's history mainRepository.push() .setRemote("origin") .setRefSpecs(new RefSpec(branch)) .setPushTags() .setForce(true) .call(); } }
@Override public void push(Git git, String branch) throws GitAPIException { git.push() .setRemote("origin") .setRefSpecs(new RefSpec(branch)) .setPushTags() .setForce(true) .call(); // in fabric env we synchronize changes with "local" git repo, which will be then (from fabric-agent) // pushed further to cluster's git repo if (master && mainRepository != null && !branch.startsWith("patch-") && !branch.equals(getMainBranchName())) { // we don't push "patch-*" branches to central repo (we push "patches-*") // getMainBranchName() is used to track current container's history mainRepository.push() .setRemote("origin") .setRefSpecs(new RefSpec(branch)) .setPushTags() .setForce(true) .call(); } }
@Override public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { org.eclipse.jgit.transport.CredentialsProvider provider = new UsernamePasswordCredentialsProvider(username, password); org.eclipse.jgit.api.Git git = org.eclipse.jgit.api.Git.open(new File(uri)); try { PushCommand pc = git.push().setRemote(targetUri) .setCredentialsProvider(provider) .setDryRun(true) .setPushTags(); pc.call(); } catch(GitAPIException e) { throw new IOException(e); } finally { if (git.getRepository() != null) { git.getRepository().close(); } } return null; } }
@Override public Object call(Git git, GitContext context) throws Exception { ProfileRegistry registry = fabricService.adapt(ProfileRegistry.class); Map<String, String> properties = registry.getDataStoreProperties(); String username; String password; if (properties != null && properties.containsKey("gitRemoteUser") && properties.containsKey("gitRemotePassword")) { username = properties.get("gitRemoteUser"); password = properties.get("gitRemotePassword"); } else { username = ZooKeeperUtils.getContainerLogin(runtimeProperties); password = ZooKeeperUtils.generateContainerToken(runtimeProperties, curator); } remoteUrl[0] = git.getRepository().getConfig().getString("remote", "origin", "url"); Iterable<PushResult> results = git.push() .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)) .setPushTags() .setPushAll() .call(); logPushResult(results, git.getRepository(), verbose); return null; } };
.setRemote(remote) .setPushAll() .setPushTags() .setTransportConfigCallback(transport -> { SshTransport sshTransport = (SshTransport) transport;
org.eclipse.jgit.api.PushCommand push = git.push(); push.setPushAll().setPushTags(); push.setRemote(remoteUrl);
@Override public void execute() throws GitException, InterruptedException { try (Repository repo = getRepository()) { RefSpec ref = (refspec != null) ? new RefSpec(fixRefSpec(repo)) : Transport.REFSPEC_PUSH_ALL; listener.getLogger().println("RefSpec is \""+ref+"\"."); Git g = git(repo); Config config = g.getRepository().getConfig(); config.setString("remote", "org_jenkinsci_plugins_gitclient_JGitAPIImpl", "url", remote.toPrivateASCIIString()); org.eclipse.jgit.api.PushCommand pc = g.push().setRemote("org_jenkinsci_plugins_gitclient_JGitAPIImpl").setRefSpecs(ref) .setProgressMonitor(new JGitProgressMonitor(listener)) .setCredentialsProvider(getProvider()) .setForce(force); if(tags) { pc.setPushTags(); } Iterable<PushResult> results = pc.call(); for(PushResult result:results) for(RemoteRefUpdate update:result.getRemoteUpdates()) { RemoteRefUpdate.Status status = update.getStatus(); if(!OK.equals(status)&&!UP_TO_DATE.equals(status)) { throw new GitException(update.getMessage() + " " + status + " for '" + ref + "' refspec '" + refspec + "' to " + remote.toPrivateASCIIString()); } } config.unset("remote", "org_jenkinsci_plugins_gitclient_JGitAPIImpl", "url"); } catch (IOException | JGitInternalException | GitAPIException e) { throw new GitException(e); } }
@Override protected void run() throws Exception { Git git = new Git(db); PushCommand push = git.push(); push.setDryRun(dryRun); push.setForce(force); push.setProgressMonitor(new TextProgressMonitor()); push.setReceivePack(receivePack); push.setRefSpecs(refSpecs); if (all) push.setPushAll(); if (tags) push.setPushTags(); push.setRemote(remote); push.setThin(thin); push.setTimeout(timeout); Iterable<PushResult> results = push.call(); for (PushResult result : results) { ObjectReader reader = db.newObjectReader(); try { printPushResult(reader, result.getURI(), result); } finally { reader.release(); } } }
git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setPushTags().call();
git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setPushTags().call();