@Signature public Memory stashCreate(ArrayMemory settings) throws GitAPIException { StashCreateCommand command = getWrappedObject().stashCreate(); if (settings != null) { command.setIncludeUntracked(settings.valueOfIndex("includeUntracked").toBoolean()); Memory indexMessage = settings.valueOfIndex("indexMessage"); if (indexMessage.isNotNull()) { command.setIndexMessage(indexMessage.toString()); } Memory ref = settings.valueOfIndex("ref"); if (ref.isNotNull()) { command.setRef(ref.toString()); } Memory workingDirectoryMessage = settings.valueOfIndex("workingDirectoryMessage"); if (workingDirectoryMessage.isNotNull()) { command.setWorkingDirectoryMessage(workingDirectoryMessage.toString()); } } return GitUtils.valueOf(command.call()); }
public static void stash(Path repositoryDirectory, String stashId) { Git git = null; try { log.debug("Stashing change from <" + repositoryDirectory + "> to stash <" + stashId + ">"); git = Git.open(repositoryDirectory.toFile()); Collection<RevCommit> stashes = git.stashList().call(); int stashIndex = 0; for (RevCommit stash : stashes) { if (stash.getFullMessage().equals(stashId)) { git.stashDrop().setStashRef(stashIndex).call(); log.warn("Stash <" + stashId + "> was already existing in <" + repositoryDirectory + ">. It has been deleted."); break; } stashIndex++; } git.stashCreate().setIncludeUntracked(true).setWorkingDirectoryMessage(stashId).call(); } catch (IOException | GitAPIException e) { throw new GitException("Failed to stash data", e); } finally { close(git); } }