Java Code Examples for org.eclipse.jgit.api.Git#stashList()

The following examples show how to use org.eclipse.jgit.api.Git#stashList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitStashHandlerV1.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Helper method extracting the StashRef for the stash commit rev
 * 
 * @param git
 *            Git handler object
 * @param stashRev
 *            Git commit name
 * @return StashRef wrapper object or <code>null</code> if the given commit is not present in the stash
 * @throws InvalidRefNameException
 * @throws GitAPIException
 */
protected StashRef getStashRef(Git git, String stashRev) throws InvalidRefNameException, GitAPIException {

	if (stashRev == null)
		return null;

	StashListCommand stashList = git.stashList();
	Collection<RevCommit> stashedRefsCollection = stashList.call();

	int k = 0;
	for (RevCommit rev : stashedRefsCollection)
		if (stashRev.equals(rev.getName()))
			return new StashRef(k);
		else
			++k;

	return null;
}
 
Example 2
Source File: GitStashHandlerV1.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean handleGet(RequestInfo requestInfo) throws ServletException {

	HttpServletRequest request = requestInfo.request;
	HttpServletResponse response = requestInfo.response;
	Repository db = requestInfo.db;

	int page = request.getParameter("page") != null ? new Integer(request.getParameter("page")).intValue() : 1; //$NON-NLS-1$ //$NON-NLS-2$
	int pageSize = request.getParameter("pageSize") != null ? new Integer(request.getParameter("pageSize")).intValue() : PAGE_SIZE; //$NON-NLS-1$ //$NON-NLS-2$
	String messageFilter = request.getParameter("filter"); //$NON-NLS-1$
	try {

		URI baseLocation = getURI(request);
		URI cloneLocation = BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.COMMIT);

		Git git = Git.wrap(db);
		StashListCommand stashList = git.stashList();
		Collection<RevCommit> stashedRefsCollection = stashList.call();

		StashPage stashPage = new StashPage(cloneLocation, db, stashedRefsCollection, page, pageSize, messageFilter);
		OrionServlet.writeJSONResponse(request, response, stashPage.toJSON());
		return true;

	} catch (Exception ex) {
		String msg = "An error occured for stash command.";
		return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, ex));
	}
}
 
Example 3
Source File: GitStashHandlerV1.java    From orion.server with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Helper method returning whether the stash is empty or not
 * 
 * @param git
 *            Git handler object
 * @return <code>true</code> iff the git stash is empty
 * @throws InvalidRefNameException
 * @throws GitAPIException
 */
protected boolean isStashEmpty(Git git) throws InvalidRefNameException, GitAPIException {
	StashListCommand stashList = git.stashList();
	Collection<RevCommit> stashedRefsCollection = stashList.call();
	return stashedRefsCollection.isEmpty();
}