Search in sources :

Example 1 with StashApplyFailureWithStatusException

use of com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method applyStash.

/**
 * Apply the given stash.
 *
 * @param stashRef the stash which will be applied.
 *
 * @return the status for stash apply operation.
 *
 * @throws GitAPIException
 */
public StashApplyStatus applyStash(String stashRef) throws GitAPIException {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.STASH_APPLY));
    StashApplyStatus status = StashApplyStatus.NOT_APPLIED_UNKNOWN_CAUSE;
    try {
        checkIfStashIsApplicable(stashRef);
        git.stashApply().setStashRef(stashRef).call();
        status = StashApplyStatus.APPLIED_SUCCESSFULLY;
        fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.STASH_APPLY));
    } catch (StashApplyFailureWithStatusException e) {
        status = e.getStatus();
        displayStashApplyFailedCauseMessage(false, status, e);
    } catch (StashApplyFailureException | IOException e) {
        displayStashApplyFailedCauseMessage(false, status, e);
    }
    return status;
}
Also used : GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) StashApplyStatus(com.oxygenxml.git.view.stash.StashApplyStatus) StashApplyFailureWithStatusException(com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException) StashApplyFailureException(org.eclipse.jgit.api.errors.StashApplyFailureException) IOException(java.io.IOException)

Example 2 with StashApplyFailureWithStatusException

use of com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method popStash.

/**
 * Pop the given stash.
 *
 * @param stashRef the stash which will be applied.
 *
 * @return the status for stash apply operation.
 *
 * @throws GitAPIException
 */
public StashApplyStatus popStash(String stashRef) throws GitAPIException {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.STASH_APPLY));
    StashApplyStatus status = StashApplyStatus.NOT_APPLIED_UNKNOWN_CAUSE;
    try {
        checkIfStashIsApplicable(stashRef);
        git.stashApply().setStashRef(stashRef).call();
        List<RevCommit> stashes = new ArrayList<>(listStashes());
        status = StashApplyStatus.APPLIED_SUCCESSFULLY;
        for (int i = 0; i < stashes.size(); i++) {
            if (stashRef.equals(stashes.get(i).getName())) {
                dropStash(i);
                break;
            }
        }
        fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.STASH_APPLY));
    } catch (StashApplyFailureWithStatusException e) {
        status = e.getStatus();
        displayStashApplyFailedCauseMessage(true, status, e);
    } catch (StashApplyFailureException | IOException e) {
        displayStashApplyFailedCauseMessage(true, status, e);
    }
    return status;
}
Also used : GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) StashApplyStatus(com.oxygenxml.git.view.stash.StashApplyStatus) StashApplyFailureWithStatusException(com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException) ArrayList(java.util.ArrayList) StashApplyFailureException(org.eclipse.jgit.api.errors.StashApplyFailureException) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 3 with StashApplyFailureWithStatusException

use of com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method checkIfStashIsApplicable.

/**
 * @param stashRef       The stash reference.
 *
 * @throws IOException
 * @throws GitAPIException
 */
private void checkIfStashIsApplicable(String stashRef) throws IOException, GitAPIException {
    List<FileStatus> list = RevCommitUtil.getChangedFiles(stashRef);
    List<FileStatus> unstagedFiles = new ArrayList<>(getUnstagedFiles());
    for (FileStatus fileStatus : list) {
        for (FileStatus file : unstagedFiles) {
            if (file.getChangeType() == GitChangeType.CONFLICT) {
                throw new StashApplyFailureWithStatusException(StashApplyStatus.CANNOT_START_APPLY_BECAUSE_CONFLICTS, "Impossible to apply");
            } else if (file.getFileLocation().compareTo(fileStatus.getFileLocation()) == 0) {
                throw new StashApplyFailureWithStatusException(StashApplyStatus.CANNOT_START_APPLY_BECAUSE_UNCOMMITTED_FILES, "Impossible to apply");
            }
        }
        if (!getStagedFiles().isEmpty()) {
            throw new StashApplyFailureWithStatusException(StashApplyStatus.CANNOT_START_BECAUSE_STAGED_FILES, "Impossible to apply");
        }
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) StashApplyFailureWithStatusException(com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException) ArrayList(java.util.ArrayList)

Aggregations

StashApplyFailureWithStatusException (com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException)3 BranchGitEventInfo (com.oxygenxml.git.view.event.BranchGitEventInfo)2 FileGitEventInfo (com.oxygenxml.git.view.event.FileGitEventInfo)2 GitEventInfo (com.oxygenxml.git.view.event.GitEventInfo)2 WorkingCopyGitEventInfo (com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)2 StashApplyStatus (com.oxygenxml.git.view.stash.StashApplyStatus)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 StashApplyFailureException (org.eclipse.jgit.api.errors.StashApplyFailureException)2 FileStatus (com.oxygenxml.git.service.entities.FileStatus)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1