Search in sources :

Example 1 with DetachedHeadDialog

use of com.oxygenxml.git.view.dialog.DetachedHeadDialog 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)

Aggregations

NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 DetachedHeadDialog (com.oxygenxml.git.view.dialog.DetachedHeadDialog)1 IOException (java.io.IOException)1 RevisionSyntaxException (org.eclipse.jgit.errors.RevisionSyntaxException)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1