push.setAtomic(settings.valueOfIndex("atomic").toBoolean()); push.setDryRun(settings.valueOfIndex("dryRun").toBoolean()); push.setForce(settings.valueOfIndex("force").toBoolean());
PushCommand pushCommand = git.push(); pushCommand.setForce( true ); pushCommand.add( "refs/*:refs/*" );
public Iterable<PushResult> forcePush(Git git, String login, String password) throws GitAPIException { val result = git.push() .setCredentialsProvider(new UsernamePasswordCredentialsProvider(login, password)) .setForce(true) .call(); logPushResultDetails(result); return result; }
private void push(Git git) throws GitAPIException { git.push() .setRemote(remote) .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 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(); } }
private void push(Git git) throws GitAPIException { git.push() .setRemote(remote) .setForce(true) .call(); }
/** * @inheritDoc */ @Override public Iterable<PushResult> push(Git git, String username, String password, String reference, String remote, boolean force) { UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password); try { Iterable<PushResult> results = git .push() .setCredentialsProvider(credentialsProvider) .add(reference) .setRemote(remote) .setForce(force) .call(); for(PushResult result : results){ RemoteRefUpdate update = result.getRemoteUpdate(reference); RemoteRefUpdate.Status status = update.getStatus(); if(!(status.equals(RemoteRefUpdate.Status.OK)||status.equals(RemoteRefUpdate.Status.UP_TO_DATE))){ throw new RuntimeException("Failed to push changes to origin"); } } return results; } catch (GitAPIException e) { throw new RuntimeException("Failed to push to origin", e); } }
public void execute() throws InvalidRemoteException { try { final List<RefSpec> specs = new UpdateRemoteConfig(git, remote, refSpecs).execute(); git._push() .setCredentialsProvider(credentialsProvider) .setRefSpecs(specs) .setRemote(remote.getK1()) .setForce(force) .setPushAll() .call(); } catch (final InvalidRemoteException e) { throw e; } catch (final Exception ex) { throw new RuntimeException(ex); } } }
public URI push(File source, String name) throws Exception { init(); File gitRoot = new File("target", name); FileUtils.copyDirectory(source, gitRoot); // Push via port forward String repoUrl = String.format("http://localhost:%s/%s", GIT_LOCALPORT, name); Git git = Git.init().setDirectory(gitRoot).call(); Repository repo = git.getRepository(); repo.getConfig().setString("remote", "origin", "url", repoUrl); repo.getConfig().save(); git.add().addFilepattern(".").call(); git.commit().setMessage("testing").setAuthor("Arquillian", "cube@discuss.arquillian.org").call(); git.push().setRemote("origin").setPushAll().setForce(true).call(); repo.close(); // Return an internal service name, for use within the openshift network String serverUrl = String.format("http://%s:%s/%s", GIT_SERVICE, GIT_REMOTEPORT, name); return URI.create(serverUrl); }
/** * Creates a branch in the remote repository from which the the current git repository was cloned. * The branch is created from the commit passed and given the name that is passed in. * * @param commit - RevCommit that is to be pushed. * @param submitName - The name of the remote branch to be created. * @throws GitAPIException - failed * @throws IOException - failed */ public void createPullRequest(final RevCommit commit, final String submitName) throws GitAPIException, IOException { markAsSubmitted(commit); git.push() .setRemote("origin") .setPushAll() .setForce(true) .setRefSpecs(new RefSpec("HEAD:refs/heads/" + submitName)) .call(); }
git.add().addFilepattern(".").call(); git.commit().setMessage("commit").call(); PushCommand command = git.push().setForce(true); command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); command.call();
public void stageAndPushDeletedFile() { try { Git git = this.gitOpen(gitDir); git.add().addFilepattern(".").setUpdate(true).call(); git.commit().setMessage("wipe").call(); PushCommand command = git.push().setForce(true); command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); command.call(); } catch (GitAPIException e) { log.error(e.getMessage(), e); } }
@Override public Status call() throws Exception { LOG.info("Starting repository synchronization"); try (Git git = getWorkingFileRepository()) { // Set fetch repo config.configure(git.remoteSetUrl(), fetchUrl, false).call(); config.configure(git.remoteSetUrl(), pushRepository, true).call(); // Fetch repo config.configure(git.fetch()).setCheckFetchedObjects(true).call(); // Push repo config.configure(git.push()).setForce(true).call(); // Sync working tree return pushRepository.call(); } finally { LOG.info("Finished repository synchronization"); // Close repository and free resources config.getWorkingFileRepository().close(); } }
cmd.setRefSpecs(new RefSpec("HEAD:refs/heads/master")) setForce(true)
@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); } }
pushCommand.setForce(true);
@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(); } } }
pushCommand.setForce(true);