Search in sources :

Example 11 with NoRepositorySelected

use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.

the class RevertCommitAction method actionPerformed.

/**
 * Action performed.
 */
@Override
public void actionPerformed(ActionEvent e) {
    Translator translator = Translator.getInstance();
    int result = FileStatusDialog.showQuestionMessage(translator.getTranslation(Tags.REVERT_COMMIT), translator.getTranslation(Tags.REVERT_COMMIT_CONFIRMATION), translator.getTranslation(Tags.YES), translator.getTranslation(Tags.NO));
    if (result == OKCancelDialog.RESULT_OK) {
        GitOperationScheduler.getInstance().schedule(() -> {
            try {
                GitAccess.getInstance().revertCommit(commitCharacteristics.getCommitId());
            } catch (IOException | NoRepositorySelected | GitAPIException ex) {
                LOGGER.debug(ex.getMessage(), ex);
                PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(ex.getMessage(), ex);
            }
        });
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) Translator(com.oxygenxml.git.translator.Translator) IOException(java.io.IOException)

Example 12 with NoRepositorySelected

use of com.oxygenxml.git.service.NoRepositorySelected 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)

Example 13 with NoRepositorySelected

use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.

the class OxygenGitPluginExtension method treatDetachedHead.

/**
 * Treat detached HEAD.
 *
 * @param wcEventInfo event info.
 */
private void treatDetachedHead(WorkingCopyGitEventInfo wcEventInfo) {
    if (wcEventInfo.isWorkingCopySubmodule()) {
        return;
    }
    Repository repo = null;
    try {
        repo = GitAccess.getInstance().getRepository();
    } catch (NoRepositorySelected e) {
        LOGGER.error(e.getMessage(), e);
    }
    if (repo != null && repo.getRepositoryState() != RepositoryState.REBASING_MERGE) {
        String commitFullID = GitAccess.getInstance().getBranchInfo().getBranchName();
        try (RevWalk revWalk = new RevWalk(repo)) {
            RevCommit commit = revWalk.parseCommit(repo.resolve(commitFullID));
            DetachedHeadDialog dlg = new DetachedHeadDialog(commit);
            dlg.setVisible(true);
        } catch (RevisionSyntaxException | IOException e) {
            LOGGER.debug(e.getMessage(), e);
        }
    }
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) Repository(org.eclipse.jgit.lib.Repository) RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) DetachedHeadDialog(com.oxygenxml.git.view.dialog.DetachedHeadDialog) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 14 with NoRepositorySelected

use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.

the class BranchSelectionCombo method refresh.

/**
 * Refresh.
 */
public void refresh() {
    int pullsBehind = GIT_ACCESS.getPullsBehind();
    int pushesAhead = -1;
    try {
        pushesAhead = GIT_ACCESS.getPushesAhead();
    } catch (RepoNotInitializedException e) {
        LOGGER.debug(e.getMessage(), e);
    }
    // update pop up
    updateBranchesPopup();
    Repository repo = null;
    try {
        repo = GIT_ACCESS.getRepository();
    } catch (NoRepositorySelected e) {
        LOGGER.debug(e.getMessage(), e);
    }
    this.setEnabled(repo != null);
    final BranchInfo branchInfo = GIT_ACCESS.getBranchInfo();
    final String currentBranchName = branchInfo.getBranchName();
    if (branchInfo.isDetached()) {
        detachedHeadId = currentBranchName;
        String tooltipText = TRANSLATOR.getTranslation(Tags.TOOLBAR_PANEL_INFORMATION_STATUS_DETACHED_HEAD) + " " + currentBranchName;
        if (repo != null && repo.getRepositoryState() == RepositoryState.REBASING_MERGE) {
            tooltipText += "<br>" + TRANSLATOR.getTranslation(Tags.REBASE_IN_PROGRESS) + ".";
        }
        tooltipText = TextFormatUtil.toHTML(tooltipText);
        String finalText = tooltipText;
        SwingUtilities.invokeLater(() -> this.setToolTipText(finalText));
    } else {
        detachedHeadId = null;
        String branchTooltip = null;
        if (currentBranchName != null && !currentBranchName.isEmpty()) {
            branchTooltip = getBranchTooltip(pullsBehind, pushesAhead, currentBranchName);
        }
        String branchTooltipFinal = branchTooltip;
        this.setToolTipText(branchTooltipFinal);
    }
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) Repository(org.eclipse.jgit.lib.Repository) BranchInfo(com.oxygenxml.git.service.BranchInfo) RepoNotInitializedException(com.oxygenxml.git.service.RepoNotInitializedException)

Example 15 with NoRepositorySelected

use of com.oxygenxml.git.service.NoRepositorySelected in project oxygen-git-client-addon by oxygenxml.

the class BranchSelectionCombo method tryCheckingOutBranch.

/**
 * The action performed for this Abstract Action
 *
 * @param oldBranchInfo Old branch info.
 * @param newBranchName New branch name.
 */
private void tryCheckingOutBranch(final BranchInfo oldBranchInfo, final String newBranchName) {
    final RepositoryState repoState = RepoUtil.getRepoState().orElse(null);
    if (oldBranchInfo.isDetached() && !RepoUtil.isRepoRebasing(repoState)) {
        detachedHeadId = null;
        this.removeItem(oldBranchInfo.getBranchName());
    }
    GitOperationScheduler.getInstance().schedule(() -> {
        try {
            GIT_ACCESS.setBranch(newBranchName);
            BranchesUtil.fixupFetchInConfig(GIT_ACCESS.getRepository().getConfig());
        } catch (CheckoutConflictException ex) {
            restoreCurrentBranchSelectionInMenu();
            BranchesUtil.showBranchSwitchErrorMessage();
        } catch (GitAPIException | JGitInternalException | IOException | NoRepositorySelected ex) {
            restoreCurrentBranchSelectionInMenu();
            PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(ex.getMessage(), ex);
        }
    });
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) IOException(java.io.IOException) RepositoryState(org.eclipse.jgit.lib.RepositoryState) CheckoutConflictException(org.eclipse.jgit.api.errors.CheckoutConflictException)

Aggregations

NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)28 IOException (java.io.IOException)15 File (java.io.File)10 URL (java.net.URL)8 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)8 Repository (org.eclipse.jgit.lib.Repository)6 FileStatus (com.oxygenxml.git.service.entities.FileStatus)4 MalformedURLException (java.net.MalformedURLException)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 RepoNotInitializedException (com.oxygenxml.git.service.RepoNotInitializedException)3 ActionEvent (java.awt.event.ActionEvent)3 AbstractAction (javax.swing.AbstractAction)3 BranchInfo (com.oxygenxml.git.service.BranchInfo)2 GitChangeType (com.oxygenxml.git.service.entities.GitChangeType)2 Translator (com.oxygenxml.git.translator.Translator)2 CheckoutCommitAction (com.oxygenxml.git.view.history.actions.CheckoutCommitAction)2 CreateBranchFromCommitAction (com.oxygenxml.git.view.history.actions.CreateBranchFromCommitAction)2 CreateTagAction (com.oxygenxml.git.view.history.actions.CreateTagAction)2 ResetBranchToCommitAction (com.oxygenxml.git.view.history.actions.ResetBranchToCommitAction)2 RevertCommitAction (com.oxygenxml.git.view.history.actions.RevertCommitAction)2