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; }
/** * Returs a command object used to apply a stashed commit * * @return a {@link org.eclipse.jgit.api.StashApplyCommand} * @since 2.0 */ public StashApplyCommand stashApply() { return new StashApplyCommand(repo); }
@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);
WrongRepositoryStateException, NoHeadException, StashApplyFailureException { checkCallable(); throw new NoHeadException(JGitText.get().stashApplyWithoutHead); final ObjectId stashId = getStashId(); RevCommit stashCommit = revWalk.parseCommit(stashId); if (stashCommit.getParentCount() < 2 boolean ok = ixMerger.merge(headCommit, stashIndexCommit); if (ok) { resetIndex(revWalk .parseTree(ixMerger.getResultTreeId())); } else { RevTree untrackedTree = revWalk .parseTree(untrackedCommit); resetUntracked(untrackedTree); } catch (CheckoutConflictException e) { throw new StashApplyFailureException(
/** * 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!"); } }
checkoutPath(entry, reader, new CheckoutMetadata(eolStreamType, null)); actuallyModifiedPaths.add(entry.getPathString());
System.out.println("StashDrop returned: " + call); ObjectId applied = git.stashApply().setStashRef(stash.getName()).call(); System.out.println("Applied 2nd stash as: " + applied);
WrongRepositoryStateException, NoHeadException, StashApplyFailureException { checkCallable(); throw new NoHeadException(JGitText.get().stashApplyWithoutHead); final ObjectId stashId = getStashId(); RevCommit stashCommit = revWalk.parseCommit(stashId); if (stashCommit.getParentCount() < 2 boolean ok = ixMerger.merge(headCommit, stashIndexCommit); if (ok) { resetIndex(revWalk .parseTree(ixMerger.getResultTreeId())); } else { RevTree untrackedTree = revWalk .parseTree(untrackedCommit); resetUntracked(untrackedTree); } catch (CheckoutConflictException e) { throw new StashApplyFailureException(
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<>(); }
checkoutPath(entry, reader, new CheckoutMetadata(eolStreamType, null)); actuallyModifiedPaths.add(entry.getPathString());
@Override public void stashApply(final Git repo, String... stashRef) throws GitAPIException { if (stashRef.length >= 1 && !Strings.isNullOrEmpty(stashRef[0])) { repo.stashApply().setStashRef(stashRef[0]).call(); } else { repo.stashApply().call(); } }
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; }
WrongRepositoryStateException, NoHeadException, StashApplyFailureException { checkCallable(); throw new NoHeadException(JGitText.get().stashApplyWithoutHead); final ObjectId stashId = getStashId(); RevCommit stashCommit = revWalk.parseCommit(stashId); if (stashCommit.getParentCount() < 2 boolean ok = ixMerger.merge(headCommit, stashIndexCommit); if (ok) { resetIndex(revWalk .parseTree(ixMerger.getResultTreeId())); } else { .parseTree(untrackedMerger .getResultTreeId()); resetUntracked(untrackedTree); } catch (CheckoutConflictException e) { throw new StashApplyFailureException(
/** * Returns a command object used to apply a stashed commit * * @return a {@link StashApplyCommand} * @since 2.0 */ public StashApplyCommand stashApply() { return new StashApplyCommand(repo); }
checkoutPath(entry, reader, new CheckoutMetadata(eolStreamType, null));
/** * 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); } }
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; }
/** * Returs a command object used to apply a stashed commit * * @return a {@link org.eclipse.jgit.api.StashApplyCommand} * @since 2.0 */ public StashApplyCommand stashApply() { return new StashApplyCommand(repo); }
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); } }