Search in sources :

Example 6 with GitEventInfo

use of com.oxygenxml.git.view.event.GitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method abortRebase.

/**
 * Aborts and resets the current rebase
 */
public void abortRebase() {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.ABORT_REBASE));
    GitOperationScheduler.getInstance().schedule(() -> {
        try {
            git.rebase().setOperation(Operation.ABORT).call();
            fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.ABORT_REBASE));
        } catch (GitAPIException e) {
            fireOperationFailed(new GitEventInfo(GitOperation.ABORT_REBASE), e);
            LOGGER.error(e.getMessage(), e);
        }
    });
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) 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)

Example 7 with GitEventInfo

use of com.oxygenxml.git.view.event.GitEventInfo 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 8 with GitEventInfo

use of com.oxygenxml.git.view.event.GitEventInfo 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 9 with GitEventInfo

use of com.oxygenxml.git.view.event.GitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method createStash.

/**
 * Create a new stash command.
 *
 * @param includeUntrackedFiles <code>True</code> if the stash should include the untracked files.
 * @param description           The description of stash. May be <code>null</code>.
 *
 * @return The created stash.
 */
public RevCommit createStash(boolean includeUntrackedFiles, String description) {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.STASH_CREATE));
    RevCommit stash = null;
    try {
        StashCreateCommand createStashCmd = git.stashCreate().setIncludeUntracked(includeUntrackedFiles);
        if (description != null) {
            createStashCmd.setWorkingDirectoryMessage(description);
        }
        stash = createStashCmd.call();
        fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.STASH_CREATE, getBranchInfo().getBranchName()));
    } catch (GitAPIException e) {
        if (repositoryHasConflicts()) {
            PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(TRANSLATOR.getTranslation(Tags.RESOLVE_CONFLICTS_FIRST));
        } else {
            PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(TRANSLATOR.getTranslation(Tags.STASH_CANNOT_BE_CREATED) + e.getMessage(), e);
            LOGGER.error(e.getMessage(), e);
        }
        fireOperationFailed(new BranchGitEventInfo(GitOperation.STASH_CREATE, getBranchInfo().getBranchName()), e);
    }
    return stash;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) 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) StashCreateCommand(org.eclipse.jgit.api.StashCreateCommand) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 10 with GitEventInfo

use of com.oxygenxml.git.view.event.GitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class OxygenGitPluginExtension method customizeGitStagingView.

/**
 * Customize the Git Staging view.
 *
 * @param viewInfo View information.
 */
private void customizeGitStagingView(final ViewInfo viewInfo, final GitActionsManager gitActionsManager) {
    boolean shouldRecreateStagingPanel = stagingPanel == null;
    if (shouldRecreateStagingPanel) {
        stagingPanel = new StagingPanel(gitRefreshSupport, gitController, OxygenGitPluginExtension.this, gitActionsManager);
        gitRefreshSupport.setStagingPanel(stagingPanel);
    }
    viewInfo.setComponent(stagingPanel);
    GitOperationUtil.installMouseBusyCursor(gitController, stagingPanel);
    gitController.addGitListener(new GitEventAdapter() {

        @Override
        public void operationAboutToStart(GitEventInfo info) {
        // not needed
        }

        @Override
        public void operationSuccessfullyEnded(GitEventInfo info) {
            final GitOperation operation = info.getGitOperation();
            if (operation == GitOperation.CHECKOUT || operation == GitOperation.CONTINUE_REBASE || operation == GitOperation.RESET_TO_COMMIT || operation == GitOperation.OPEN_WORKING_COPY || operation == GitOperation.MERGE || operation == GitOperation.COMMIT || operation == GitOperation.REVERT_COMMIT || operation == GitOperation.STASH_CREATE || operation == GitOperation.STASH_DROP || operation == GitOperation.STASH_APPLY || operation == GitOperation.UPDATE_CONFIG_FILE || operation == GitOperation.STASH_POP || operation == GitOperation.CHECKOUT_FILE || operation == GitOperation.CHECKOUT_COMMIT || operation == GitOperation.CREATE_TAG || operation == GitOperation.DELETE_TAG || operation == GitOperation.DISCARD) {
                gitRefreshSupport.call();
                if (operation == GitOperation.CHECKOUT || operation == GitOperation.MERGE) {
                    try {
                        FileUtil.refreshProjectView();
                    } catch (NoRepositorySelected e) {
                        LOGGER.debug(e.getMessage(), e);
                    }
                } else if (operation == GitOperation.OPEN_WORKING_COPY && GitAccess.getInstance().getBranchInfo().isDetached()) {
                    treatDetachedHead((WorkingCopyGitEventInfo) info);
                }
            }
        }

        @Override
        public void operationFailed(GitEventInfo info, Throwable t) {
            final GitOperation operation = info.getGitOperation();
            if (operation == GitOperation.CONTINUE_REBASE || operation == GitOperation.RESET_TO_COMMIT) {
                gitRefreshSupport.call();
            }
        }
    });
    gitRefreshSupport.call();
    viewInfo.setIcon(Icons.getIcon(Icons.GIT_ICON));
    viewInfo.setTitle(translator.getTranslation(Tags.GIT_STAGING));
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) GitOperation(com.oxygenxml.git.view.event.GitOperation) GitEventAdapter(com.oxygenxml.git.service.GitEventAdapter) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel)

Aggregations

GitEventInfo (com.oxygenxml.git.view.event.GitEventInfo)23 WorkingCopyGitEventInfo (com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)19 BranchGitEventInfo (com.oxygenxml.git.view.event.BranchGitEventInfo)18 FileGitEventInfo (com.oxygenxml.git.view.event.FileGitEventInfo)18 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)11 IOException (java.io.IOException)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 StashApplyStatus (com.oxygenxml.git.view.stash.StashApplyStatus)3 ArrayList (java.util.ArrayList)3 CheckoutCommand (org.eclipse.jgit.api.CheckoutCommand)3 Repository (org.eclipse.jgit.lib.Repository)3 GitController (com.oxygenxml.git.view.event.GitController)2 GitOperation (com.oxygenxml.git.view.event.GitOperation)2 StashApplyFailureWithStatusException (com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException)2 StashApplyFailureException (org.eclipse.jgit.api.errors.StashApplyFailureException)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 StandalonePluginWorkspace (ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)2 OxygenGitPluginExtension (com.oxygenxml.git.OxygenGitPluginExtension)1 SSHCapableUserCredentialsProvider (com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider)1 GitEventAdapter (com.oxygenxml.git.service.GitEventAdapter)1