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;
}
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;
}
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");
}
}
}
Aggregations