Refine search
private void addEdge(File edgeDir, File edgeFile, String fileContents) throws IOException, GitAPIException { createNewFile(edgeDir, edgeFile, fileContents); // add, commit, push edge this.gitForPush.add().addFilepattern(formEdgeFilePath(edgeDir.getParentFile().getName(), edgeDir.getName(), edgeFile.getName())).call(); this.gitForPush.commit().setMessage("Edge commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); }
@Signature public Memory push(String remote, ArrayMemory settings) throws GitAPIException { PushCommand push = getWrappedObject().push(); push.setRemote(remote); push.setTransportConfigCallback(transportConfigCallback); if (credentialsProvider != null) { push.setCredentialsProvider(credentialsProvider); push.setAtomic(settings.valueOfIndex("atomic").toBoolean()); push.setDryRun(settings.valueOfIndex("dryRun").toBoolean()); push.setForce(settings.valueOfIndex("force").toBoolean()); push.setPushAll(); push.setPushTags(); push.setReceivePack(receivePack.toString()); push.setThin(settings.valueOfIndex("thin").toBoolean()); push.setTimeout(timeout.toInteger()); push.setCredentialsProvider(new UsernamePasswordCredentialsProvider( credentials.valueOfIndex("username").toString(), credentials.valueOfIndex("password").toString() return GitUtils.valueOfPushResults(push.call());
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile2.getName())) .call(); this.gitForPush.commit().setMessage("Fifth commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD~1").call(); this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call(); .call(); this.gitForPush.commit().setMessage("Sixth commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitForPush.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD~4").call(); this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException { Repository repository = repositoryService.createRepository(new Repository().setName(applicationName)); String cloneUrl = repository.getCloneUrl(); InitCommand init = new InitCommand(); init.setDirectory(srcFolder); init.setBare(false); Git git = init.call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", cloneUrl); config.save(); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, ""); git.add().addFilepattern(".").call(); git.commit().setMessage(COMMIT_MESSAGE).call(); git.push().setCredentialsProvider(user).call(); return repository; } }
@Override public void pushTags(Collection<AnnotatedTag> tags) throws GitAPIException { PushCommand pushCommand = git.push() .setCredentialsProvider(credentialsProvider); if (remoteUrl != null) { pushCommand.setRemote(remoteUrl); } for (AnnotatedTag tag : tags) { pushCommand.add(tag.saveAtHEAD(git)); } pushCommand.call(); }
RefSpec masterSpec = new RefSpec("+" + Constants.R_HEADS + gfConfig.getMaster() + ":" + Constants.R_REMOTES + "origin/" + gfConfig.getMaster()); git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(masterSpec).call(); git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(developSpec).call(); git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call(); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(developSpec).call(); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(masterSpec).call(); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setPushTags().call(); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(branchSpec).call(); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(deleteSpec).call();
/** * Use with care! */ public boolean deleteBranch() { if (!branch.startsWith("feature/")) { throw new GitException("Can only delete feature branch."); } try { final Git git = gitOpen(); git.checkout().setCreateBranch(true).setName("feature/temp_" + UUID.randomUUID()).call(); List<String> deletedBranches = git.branchDelete().setBranchNames(branch).setForce(true).call(); if (deletedBranches.size() == 1) { // delete branch 'branchToDelete' on remote 'origin' RefSpec refSpec = new RefSpec().setSource(null).setDestination("refs/heads/" + branch); Iterable<PushResult> results = git.push().setCredentialsProvider(credentialsProvider()).setRefSpecs(refSpec).setRemote("origin").call(); for (PushResult result : results) { RemoteRefUpdate myUpdate = result.getRemoteUpdate("refs/heads/" + branch); if (myUpdate.isDelete() && myUpdate.getStatus() == RemoteRefUpdate.Status.OK) { return true; } } } return false; } catch (IOException | GitAPIException e) { throw new GitException("Delete branch failed", e); } }
result = Git.cloneRepository().setURI(remotePath).setDirectory(new File(localPath)).call(); } catch (Exception e) { LOGGER.error("Error cloning backup git repo"); git = new Git(backupRepo); File myfile = new File(localPath + "/" + fileName); git.add().addFilepattern(".").call(); } catch (GitAPIException e) { LOGGER.error("Error adding files to git"); git.push().call(); } catch (GitAPIException e) { LOGGER.error("Error pushing files to git");
@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(); } }
Ref masterRef = git.getRepository().getRef("master"); if (null != masterRef) { commitId = ObjectId.toString(masterRef.getObjectId()); Status status = git.status().call(); git.add().setUpdate(true).addFilepattern(".").call(); cmd.setProgressMonitor(new TextProgressMonitor()); try { pushResults = cmd.setRefSpecs(new RefSpec("HEAD:refs/heads/master")) setForce(true) setRemote(remote) call(); } catch (Exception exc) {
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); }
@Override public synchronized PushPolicyResult doPush(GitContext context, CredentialsProvider credentialsProvider) { StoredConfig config = git.getRepository().getConfig(); String remoteUrl = config.getString("remote", remoteRef, "url"); if (remoteUrl == null) { try { git.clean().setCleanDirectories(true).call(); // to remove not-tracked files git.reset().setMode(ResetCommand.ResetType.MIXED).call(); // for file permissions git.reset().setMode(ResetCommand.ResetType.HARD).call(); // for other changes resit = git.push().setTimeout(gitTimeout).setCredentialsProvider(credentialsProvider) .setPushTags() .setPushAll() .call().iterator(); } catch (Exception ex) { lastException = ex;
protected void doPushNewBranchIfNeeded(JGitFlowExtension pushExtension, String branchToPush) throws GitAPIException, JGitFlowGitAPIException, JGitFlowExtensionException, RemoteBranchExistsException, IOException { if (isPush()) { enforcer().requireRemoteBranchAbsent(branchToPush); reporter.infoText(getCommandName(), "pushing new branch to origin: " + branchToPush); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(new RefSpec(gfConfig.getDevelop()), new RefSpec(branchToPush)).call(); reporter.debugText(getCommandName(), "push complete"); git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call(); //setup tracking StoredConfig config = git.getRepository().getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchToPush, ConfigConstants.CONFIG_KEY_REMOTE, Constants.DEFAULT_REMOTE_NAME); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, branchToPush, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + branchToPush); config.save(); try { config.load(); } catch (ConfigInvalidException e) { throw new JGitFlowGitAPIException("unable to load config", e); } runExtensionCommands(pushExtension.afterPush()); } }
Git git = new Git(repo); PushCommand pushCommand = git.push().setRemote(remoteName).setPushTags().setProgressMonitor(new TextProgressMonitor()); pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password)); Iterable<PushResult> results = pushCommand.call(); results = git.push().setRemote(remoteName).setRefSpecs(branchesToDelete).setProgressMonitor(new TextProgressMonitor()).call();
return false; git.checkout(). setCreateBranch(true). setName(branch). git.pull().call(); } catch (GitAPIException e) { log.info(e.getMessage()); git.add().addFilepattern(".").call(); git.commit().setMessage("commit").call(); PushCommand command = git.push().setForce(true); command.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); command.call(); } catch (GitAPIException e) { log.error(e.getMessage(), e);
/** * 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); } }
@Override public synchronized PushPolicyResult doPush(GitContext context, CredentialsProvider credentialsProvider) { StoredConfig config = git.getRepository().getConfig(); String remoteUrl = config.getString("remote", remoteRef, "url"); if (remoteUrl == null) { Exception lastException = null; try { resit = git.push().setTimeout(gitTimeout).setCredentialsProvider(credentialsProvider).setPushAll().call().iterator(); } catch (GitAPIException | JGitInternalException ex) { lastException = ex; try { GitHelpers.checkoutBranch(git, branch); FetchResult fetchResult = git.fetch().setTimeout(gitTimeout).setCredentialsProvider(credentialsProvider).setRemote(remoteRef).setRefSpecs(new RefSpec("refs/heads/" + branch)).call(); Ref fetchRef = fetchResult.getAdvertisedRef("refs/heads/" + branch); git.branchRename().setOldName(branch).setNewName(branch + "-tmp").call();
public Void call(Git git, GitContext context) throws Exception { removeVersionFromCaches(versionId); GitHelpers.removeBranch(git, versionId); git.push().setTimeout(gitTimeout) .setCredentialsProvider(getCredentialsProvider()) .setRefSpecs(new RefSpec().setSource(null).setDestination("refs/heads/" + versionId)) .call(); return null; } };
try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) try (Git result2 = Git.cloneRepository() .setURI("file://" + localPath) .setDirectory(localPath2) try (Git git = new Git(repository)) { git.push() .call();
@Override public void addCommitPush() { try { Git git = gitOpen(); git.add().addFilepattern(".").call(); // status Status status=git.status().call(); // rm the deleted ones if(status.getMissing().size() >0){ for(String rm : status.getMissing()){ git.rm().addFilepattern(rm).call(); } } // commit and push if needed if(!status.hasUncommittedChanges()){ log.debug("not commiting git, because there are no changes"); return; } git.commit().setMessage("Automatic commit by releasetrain").call(); git.push().setCredentialsProvider(credentialsProvider()).call(); } catch (Exception e) { throw new GitException(e.getMessage(), e); } }