@Signature public Memory stashApply(ArrayMemory settings) throws GitAPIException { StashApplyCommand command = getWrappedObject().stashApply(); if (settings != null) { command.setApplyIndex(settings.valueOfIndex("applyIndex").toBoolean()); command.setApplyUntracked(settings.valueOfIndex("applyUntracked").toBoolean()); Memory stashRef = settings.valueOfIndex("stashRef"); if (stashRef.isNotNull()) { command.setStashRef(stashRef.toString()); } Memory strategy = settings.valueOfIndex("strategy"); if (strategy.isNotNull()) { command.setStrategy(MergeStrategy.get(strategy.toString())); } } return GitUtils.valueOf(command.call()); }
System.out.println("StashDrop returned: " + call); ObjectId applied = git.stashApply().setStashRef(stash.getName()).call(); System.out.println("Applied 2nd stash as: " + applied);
System.out.println("StashDrop returned: " + call); ObjectId applied = git.stashApply().setStashRef(stash.getName()).call(); System.out.println("Applied 2nd stash as: " + applied);
private boolean autoStashApply() throws IOException, GitAPIException { boolean conflicts = false; if (rebaseState.getFile(AUTOSTASH).exists()) { String stash = rebaseState.readFile(AUTOSTASH); try (Git git = Git.wrap(repo)) { git.stashApply().setStashRef(stash) .ignoreRepositoryState(true).setStrategy(strategy) .call(); } catch (StashApplyFailureException e) { conflicts = true; try (RevWalk rw = new RevWalk(repo)) { ObjectId stashId = repo.resolve(stash); RevCommit commit = rw.parseCommit(stashId); updateStashRef(commit, commit.getAuthorIdent(), commit.getShortMessage()); } } } return conflicts; }
/** * This method stashes all changes since the last commit. * * @param gitConfig * @throws GitWorkflowException */ public void stashChanges(GitConfiguration gitConfig) throws GitWorkflowException { try (Git git = Git.open(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId()))) { // Open git folder // Stash changes git.stashApply().call(); } catch (Exception e) { logger.error(e.getMessage(), e); throw new GitWorkflowException("Faild to stash changes!"); } }
private Collection<String> applyStashIfNeeded() throws GitAPIException { if (!git.stashList().call().isEmpty()) { try { git.stashApply().call(); } catch (final Exception e) { val conflicts = git.status().call().getConflicting(); git.close(); return conflicts; } } return new HashSet<>(); }
/** * Clean up if something went wrong * * @param path * @param moduleName * @throws IllegalStateException */ private void cleanUp(String path, String moduleName) throws IllegalStateException { try { Repository localRepo = gitHelper.getLocalRepository(path); Git git = new Git(localRepo); if(!localRepo.getBranch().equals(userBranch)){ checkoutBranch(git, userBranch); if(stash != null){ git.stashApply().setStashRef(stash.getName()).call(); } deleteTempBranch(git, SDK_DASH + serverId); } else if(isTempBranchCreated(git)){ if(stash != null){ git.stashApply().setStashRef(stash.getName()).call(); } deleteTempBranch(git, SDK_DASH + serverId); } } catch (Exception e) { throw new IllegalStateException(String.format(CLEAN_UP_ERROR_MESSAGE, userBranch, moduleName), e); } }
public static void applyStashThenDrop(Path repositoryDirectory, String stashId) { Git git = null; try { git = Git.open(repositoryDirectory.toFile()); int stashIndex = 0; Collection<RevCommit> stashes = git.stashList().call(); for (RevCommit stash : stashes) { if (stash.getFullMessage().equals(stashId)) { git.stashApply().setStashRef(stash.getName()).call(); git.stashDrop().setStashRef(stashIndex).call(); log.debug("Stash <" + stashId + "> applied/dropped on <" + repositoryDirectory + ">"); break; } stashIndex++; } } catch (IOException | GitAPIException e) { throw new GitException("Failed to apply then drop stash", e); } finally { close(git); } }
/** * Pull from upstream * * @param git * @param stash * @param newBranch * @param previousBranch * @throws Exception */ private void pullFromRemoteUpstream(Git git, RevCommit stash, String newBranch, String previousBranch) throws Exception { try { PullCommand pull = git.pull() .setRebase(true) .setRemote(UPSTREAM) .setRemoteBranchName(branch); PullResult pullResult = pull.call(); if(!pullResult.isSuccessful()){ rebaseAbort(git); checkoutBranch(git, previousBranch); if (stash != null) { git.stashApply().setStashRef(stash.getName()).call(); } deleteTempBranch(git, newBranch); throw new Exception(CONFLICT_MESSAGE_REASON); } } catch (GitAPIException e) { throw new Exception(PULL_COMMAND_PROBLEM_REASON, e); } }
private boolean autoStashApply() throws IOException, GitAPIException { boolean conflicts = false; if (rebaseState.getFile(AUTOSTASH).exists()) { String stash = rebaseState.readFile(AUTOSTASH); try { Git.wrap(repo).stashApply().setStashRef(stash) .ignoreRepositoryState(true).setStrategy(strategy) .call(); } catch (StashApplyFailureException e) { conflicts = true; try (RevWalk rw = new RevWalk(repo)) { ObjectId stashId = repo.resolve(stash); RevCommit commit = rw.parseCommit(stashId); updateStashRef(commit, commit.getAuthorIdent(), commit.getShortMessage()); } } } return conflicts; }
private boolean autoStashApply() throws IOException, GitAPIException { boolean conflicts = false; if (rebaseState.getFile(AUTOSTASH).exists()) { String stash = rebaseState.readFile(AUTOSTASH); try (Git git = Git.wrap(repo)) { git.stashApply().setStashRef(stash) .ignoreRepositoryState(true).setStrategy(strategy) .call(); } catch (StashApplyFailureException e) { conflicts = true; try (RevWalk rw = new RevWalk(repo)) { ObjectId stashId = repo.resolve(stash); RevCommit commit = rw.parseCommit(stashId); updateStashRef(commit, commit.getAuthorIdent(), commit.getShortMessage()); } } } return conflicts; }
if (stash != null) { try { git.stashApply().setStashRef(stash.getName()).call(); checkoutBranch(git, userBranch); mergeWithNewBranch(git, newBranchFull); git.reset().setMode(ResetCommand.ResetType.HARD).setRef(userBranch).call(); checkoutBranch(git, userBranch); git.stashApply().setStashRef(stash.getName()).call(); deleteTempBranch(git, newBranch); throw new Exception(CONFLICT_MESSAGE_REASON);