Refine search
void cleanAndResetToMaster() throws IOException { try { git.reset().setMode(ResetCommand.ResetType.HARD).call(); checkout("master"); deleteBranch(BRANCH_AT_REVISION); deleteBranch(BRANCH_AT_HEAD); } catch (Exception e) { String currentBranch = git.getRepository().getBranch(); LOGGER.error("Error while trying to clean up config repository, CurrentBranch: {} \n : \n Message: {} \n StackTrace: {}", currentBranch, e.getMessage(), e.getStackTrace(), e); throw new RuntimeException(e); } }
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(); this.gitForPush.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD~4").call(); this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();
ObjectId oldHeadTree = git.getRepository().resolve(this.lastProcessedGitHash + "^{tree}"); this.git.fetch() .setRemote(REMOTE_NAME) .setCredentialsProvider(getCredentialsProvider()) .call(); this.git.reset().setMode(ResetCommand.ResetType.HARD).setRef(REMOTE_NAME + "/" + this.branchName).call(); ObjectId head = this.git.getRepository().resolve("HEAD");
ObjectId since = fork.getRepository().resolve("HEAD^{commit}"); ObjectId to = fork.getRepository().resolve(gitPatchRepository.getMainBranchName() + "^{commit}"); Iterable<RevCommit> mainChanges = fork.log().addRange(since, to).call(); List<RevCommit> userChanges = new LinkedList<>(); fork.reset() .setMode(ResetCommand.ResetType.HARD) .setRef("refs/tags/" + patchRef + "^{commit}") .call(); fork.reset().setMode(ResetCommand.ResetType.HARD).call(); fork.reset().setMode(ResetCommand.ResetType.HARD).call();
RevCommit c1 = new RevWalk(fork.getRepository()) .parseCommit(fork.getRepository().resolve(currentBaseline.getTagName() + "^{commit}")); RevCommit c2 = new RevWalk(fork.getRepository()) .parseCommit(fork.getRepository().resolve("HEAD")); RevCommit to = c2; fork.reset() .setMode(ResetCommand.ResetType.HARD) .setRef(previousBaseline.getTagName() + "^{commit}") .call(); fork.reset() .setMode(ResetCommand.ResetType.MIXED) .call(); for (String p : status.getModified()) { gitPatchRepository.checkout(fork).addPath(p).call();
Git git = null; try { git = Git.open(gitRepository); git.checkout() .setCreateBranch(false) .setName(versionBranch) .call(); MergeResult result = git.merge() .setFastForward(MergeCommand.FastForwardMode.NO_FF) .include(git.getRepository().resolve(patchBranch)) " patch branch \"" + patchBranch + "\". Resetting the branch."); git.reset() .setMode(ResetCommand.ResetType.HARD) .call();
@Override public synchronized PullPolicyResult doPull(GitContext context, CredentialsProvider credentialsProvider, boolean allowVersionDelete, boolean allowPush, int timeoutInSeconds) { Repository repository = git.getRepository(); StoredConfig config = repository.getConfig(); String remoteUrl = config.getString("remote", remoteRef, "url"); for (Ref ref : git.lsRemote().setTimeout(timeoutInSeconds).setCredentialsProvider(credentialsProvider) .setTags(false) .setHeads(true) git.fetch().setTimeout(timeoutInSeconds).setCredentialsProvider(credentialsProvider) .setTagOpt(TagOpt.FETCH_TAGS) .setRemote(remoteRef).call(); if (branch.equals(git.getRepository().getBranch())) { 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 git.checkout().setName("master").call(); LOGGER.info("Local branch {} is up to date, but not clean. Cleaning working copy now.", branch); 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
if (fork.getRepository().getRef("refs/heads/" + gitPatchRepository.getMainBranchName()) == null) { String startPoint = "patch-management^{commit}"; if (fork.getRepository().getRef("refs/remotes/origin/" + gitPatchRepository.getMainBranchName()) != null) { startPoint = "refs/remotes/origin/" + gitPatchRepository.getMainBranchName(); ObjectId since = fork.getRepository().resolve("patch-management^{commit}"); ObjectId to = fork.getRepository().resolve(gitPatchRepository.getMainBranchName() + "^{commit}"); fork.reset() .setMode(ResetCommand.ResetType.HARD) .setRef(String.format(env.getBaselineTagFormat(), version)) .call(); fork.reset().setMode(ResetCommand.ResetType.MIXED).call(); fork.reset().setMode(ResetCommand.ResetType.HARD).call(); fork.reset().setMode(ResetCommand.ResetType.MIXED).call(); fork.reset().setMode(ResetCommand.ResetType.HARD).call();
@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)
return false; PullCommand pullCommand = git.pull() .setRemote(mRemote) .setProgressMonitor(new BasicProgressMonitor()) String branch = null; if (mForcePull) { branch = git.getRepository().getFullBranch(); if (!branch.startsWith("refs/heads/")) { setException(new GitAPIException("not on branch") {}, bpm.beginTask("clearing repo state", 3); git.getRepository().writeMergeCommitMsg(null); git.getRepository().writeMergeHeads(null); bpm.update(1); git.reset().setMode(ResetCommand.ResetType.HARD) .setRef("HEAD").call(); bpm.endTask(); BasicProgressMonitor bpm = new BasicProgressMonitor(); bpm.beginTask("resetting to " + mRemote + "/" + branch, 1); git.reset().setMode(ResetCommand.ResetType.HARD) .setRef(mRemote + "/" + branch).call(); bpm.endTask();
if (gitDir.exists() && gitDir.isDirectory()) { repository = Git.open(localDirectory).getRepository(); try (Git git = new Git(repository)) { git.submoduleInit().call(); git.submoduleUpdate().call(); try (Git git = new Git(repository)) { git.reset().setMode(ResetType.HARD).call();
Set<String> removedFiles = git.clean().setCleanDirectories(true).call(); for (String removedFile : removedFiles) { log.debug("srcdeps: Removed an unstaged file [{}]", removedFile); git.reset().setMode(ResetType.HARD).call(); final String startPoint; final String refToFetch; final FetchCommand fetch = git.fetch().setRemote(remoteAlias); switch (srcVersion.getWellKnownType()) { case branch: git.branchCreate().setName(SRCDEPS_WORKING_BRANCH).setForce(true).setStartPoint(startPoint).call(); git.checkout().setName(SRCDEPS_WORKING_BRANCH).call(); git.reset().setMode(ResetType.HARD).setRef(startPoint).call(); final Ref ref = git.getRepository().exactRef("HEAD");
@Override public Void call() { try { LOGGER.info("Undo local changes due to failure of git operations"); try { git.rebase().setOperation(RebaseCommand.Operation.ABORT).call(); } catch (WrongRepositoryStateException e) { // ignore rebasing exception when in wrong state } final String remoteBranch = Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + '/' + git.getRepository().getBranch(); git.reset().setMode(ResetType.HARD).setRef(remoteBranch).call(); git.clean().setCleanDirectories(true).call(); try { final ObjectId head = git.getRepository().resolve(Constants.HEAD); LOGGER.info("Undo local changes completed. HEAD is " + head.getName()); } catch (final Exception e) { LOGGER.warn("Failed to fetch HEAD", e); } } catch (final Exception e) { LOGGER.error("Unable to undo changes", e); } return null; } });
/** * Fetch the version of a config after a particular commit in its history * * @param jobId The job id to check * @param commitId The commit id to fetch * @return The contents of the file after the specified time * @throws GitAPIException If there is a problem retrieving the file after the specified commit * @throws IOException If there is a problem writing to the file */ public String fetchJobConfigFromHistory(String jobId, String commitId) throws GitAPIException, IOException { synchronized (gitDir) { File file = getFileForJobId(jobId); git.checkout().addPath(getPathForJobId(jobId)).setStartPoint(commitId).setName("master").call(); String rv = new String(LessFiles.read(file)); git.reset().setMode(ResetCommand.ResetType.HARD).call(); return rv; } }
@Override public void switchToVersion(String version) throws Exception { try (Git git = new Git(repository)) { if (version == null) { version = REMOTE_BRANCH; // TODO fetch git.fetch().setRemote(REMOTE).call(); } Log.logDebug(LOGGER, "GIT switchToVersion {0} ", version); git.reset().setMode(ResetType.HARD).call(); git.checkout().setName(version).call(); git.branchDelete().setForce(true).setBranchNames(LOCAL_BRANCH).call(); git.checkout().setCreateBranch(true).setName(LOCAL_BRANCH).setStartPoint(version).call(); } catch (TransportException e) { throw new NetworkException(e); } }
Git git = new Git(localRepo); stash = git.stashCreate().call(); gitHelper.addRemoteUpstream(git, path); pullFromRemoteUpstream(git, stash, newBranch, userBranch); if (stash != null) { try { git.stashApply().setStashRef(stash.getName()).call(); checkoutBranch(git, userBranch); mergeWithNewBranch(git, newBranchFull); deleteTempBranch(git, newBranch); } catch (StashApplyFailureException e) { git.reset().setMode(ResetCommand.ResetType.HARD).setRef(userBranch).call(); checkoutBranch(git, userBranch); git.stashApply().setStashRef(stash.getName()).call();
public static Boolean pullAndRebase(final Git git) { Boolean result = Boolean.FALSE; try { git.reset().setMode(ResetCommand.ResetType.HARD).call(); final RebaseResult rr = git.pull().setRemote(REMOTE).setRebase(Boolean.TRUE).call().getRebaseResult(); if (rr.getStatus().equals(RebaseResult.Status.UP_TO_DATE) || rr.getStatus().equals(RebaseResult.Status.FAST_FORWARD)) { result = Boolean.TRUE; } if (rr.getStatus().equals(RebaseResult.Status.UNCOMMITTED_CHANGES)) { PullResult pr = git.pull().call(); if (pr.isSuccessful()) { result = Boolean.TRUE; } else { result = Boolean.FALSE; } } } catch (Exception e) { logger.error(e.getMessage()); } return result; }
/** {@inheritDoc} */ @Deprecated @Override public void reset(boolean hard) throws GitException, InterruptedException { try (Repository repo = getRepository()) { ResetCommand reset = new ResetCommand(repo); reset.setMode(hard?HARD:MIXED); reset.call(); } catch (GitAPIException e) { throw new GitException(e); } }