Search in sources :

Example 1 with WhenRepoDetectedInProject

use of com.oxygenxml.git.OxygenGitOptionPagePluginExtension.WhenRepoDetectedInProject in project oxygen-git-client-addon by oxygenxml.

the class PanelRefresh method tryToSwitchToRepo.

/**
 * Try to switch to repo, if the user will agree.
 *
 * @param repoDir Repository directory.
 *
 * @return <code>true</code> if repo changed.
 */
private boolean tryToSwitchToRepo(File repoDir) {
    boolean repoChanged = false;
    try {
        File currentRepo = null;
        if (gitAccess.isRepoInitialized()) {
            currentRepo = gitAccess.getRepository().getDirectory().getParentFile();
        }
        if (currentRepo == null || !same(currentRepo, repoDir)) {
            JComboBox<String> wcComboBox = stagingPanel.getWorkingCopySelectionPanel().getWorkingCopyCombo();
            if (wcComboBox.isPopupVisible()) {
                wcComboBox.setPopupVisible(false);
            }
            WhenRepoDetectedInProject whatToDo = OptionsManager.getInstance().getWhenRepoDetectedInProject();
            String projectDirPath = getCanonicalPath(repoDir);
            if (whatToDo == WhenRepoDetectedInProject.ASK_TO_SWITCH_TO_WC) {
                repoChanged = switchToProjectRepoIfUserAgrees(projectDirPath);
            } else if (whatToDo == WhenRepoDetectedInProject.AUTO_SWITCH_TO_WC) {
                GitAccess.getInstance().setRepositoryAsync(projectDirPath);
                repoChanged = true;
            }
        }
    } catch (NoRepositorySelected e) {
        LOGGER.warn(e.getMessage(), e);
    }
    return repoChanged;
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) WhenRepoDetectedInProject(com.oxygenxml.git.OxygenGitOptionPagePluginExtension.WhenRepoDetectedInProject) File(java.io.File)

Aggregations

WhenRepoDetectedInProject (com.oxygenxml.git.OxygenGitOptionPagePluginExtension.WhenRepoDetectedInProject)1 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 File (java.io.File)1