Skip to content

Commit

Permalink
EXM-46411: fire events for "Show history" + lowered method complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
sorincarbunaru committed Jul 31, 2024
1 parent 76a4717 commit 1772b45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
30 changes: 18 additions & 12 deletions src/main/java/com/oxygenxml/git/service/GitAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2235,10 +2235,13 @@ private void skipCommit() {
* @return a Vector with commits characteristics of the current repository.
*/
public List<CommitCharacteristics> getCommitsCharacteristics(HistoryStrategy strategy, String filePath, RenameTracker renameTracker) {
// TODO EXM-46411 I think we need to fire start, ended, failed here as well
try {
fireOperationAboutToStart(new GitEventInfo(GitOperation.SHOW_HISTORY));
} catch (IndexLockExistsException e) {
// Ignore. The history can be shown.
}

List<CommitCharacteristics> revisions = new ArrayList<>();

try {
Repository repository = this.getRepository();
if (filePath == null && statusCache.getStatus().hasUncommittedChanges()) {
Expand All @@ -2262,8 +2265,10 @@ public List<CommitCharacteristics> getCommitsCharacteristics(HistoryStrategy str
break;
}

fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.SHOW_HISTORY));
} catch (NoWorkTreeException | NoRepositorySelected | IOException e) {
LOGGER.error(e.getMessage(), e);
fireOperationFailed(new GitEventInfo(GitOperation.SHOW_HISTORY), e);
}

return revisions;
Expand Down Expand Up @@ -2447,23 +2452,24 @@ private void internalMerge(final String branchName, boolean isSquash, final Stri
}

final MergeResult res = mergeCommand.call();
if (res.getMergeStatus().equals(MergeResult.MergeStatus.CONFLICTING)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("We have conflicts here: {}", res.getConflicts());
}
final List<String> conflictingFiles = new ArrayList<>(res.getConflicts().keySet());
MergeStatus mergeStatus = res.getMergeStatus();
if (mergeStatus.equals(MergeResult.MergeStatus.CONFLICTING)) {
Map<String, int[][]> conflicts = res.getConflicts();
LOGGER.debug("We have conflicts here: {}", conflicts);

final List<String> conflictingFiles = new ArrayList<>(conflicts.keySet());
MessagePresenterProvider.getBuilder(
TRANSLATOR.getTranslation(Tags.MERGE_CONFLICTS_TITLE), DialogType.WARNING)
.setTargetFilesWithTooltips(FileStatusUtil.comuteFilesTooltips(new ArrayList<>(conflictingFiles)))
.setMessage(TRANSLATOR.getTranslation(Tags.MERGE_CONFLICTS_MESSAGE))
.setCancelButtonVisible(false)
.buildAndShow();
fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.MERGE, branchName));
} else if (res.getMergeStatus().equals(MergeResult.MergeStatus.FAILED)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Failed because of this files: {}", res.getFailingPaths());
}
final List<String> failingFiles = new ArrayList<>(res.getFailingPaths().keySet());
} else if (mergeStatus.equals(MergeResult.MergeStatus.FAILED)) {
Map<String, MergeFailureReason> failingPaths = res.getFailingPaths();
LOGGER.debug("Failed because of this files: {}", failingPaths);
final List<String> failingFiles = new ArrayList<>(failingPaths.keySet());
MessagePresenterProvider.getBuilder(
TRANSLATOR.getTranslation(Tags.MERGE_FAILED_UNCOMMITTED_CHANGES_TITLE), DialogType.ERROR)
.setTargetFilesWithTooltips(FileStatusUtil.comuteFilesTooltips(new ArrayList<>(failingFiles)))
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/oxygenxml/git/view/event/GitOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,9 @@ public enum GitOperation {
/**
* Update the config file for current repository
*/
UPDATE_CONFIG_FILE
UPDATE_CONFIG_FILE,
/**
* Show history
*/
SHOW_HISTORY
}

0 comments on commit 1772b45

Please sign in to comment.