Search in sources :

Example 1 with NoRepositorySelected

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

the class AddRemoteDialog method doOK.

/**
 * Adds the remote as origin to the repository
 */
@Override
protected void doOK() {
    super.doOK();
    StoredConfig config;
    try {
        config = GitAccess.getInstance().getRepository().getConfig();
        RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
        URIish uri = new URIish(remoteRepoTextField.getText());
        remoteConfig.addURI(uri);
        RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
        remoteConfig.addFetchRefSpec(spec);
        remoteConfig.update(config);
        config.save();
        String host = uri.getHost();
        if (!AuthenticationInterceptor.isBound(host)) {
            AuthenticationInterceptor.bind(host);
        }
    } catch (NoRepositorySelected | URISyntaxException | IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    dispose();
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) URIish(org.eclipse.jgit.transport.URIish) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) RefSpec(org.eclipse.jgit.transport.RefSpec) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 2 with NoRepositorySelected

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

the class ShowTagsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    try {
        final TagsDialog dialog = new TagsDialog();
        dialog.setVisible(true);
    } catch (GitAPIException | IOException | NoRepositorySelected ex) {
        PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(ex.getMessage(), ex);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) TagsDialog(com.oxygenxml.git.view.tags.TagsDialog) IOException(java.io.IOException)

Example 3 with NoRepositorySelected

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

the class BlameManager method doBlame.

/**
 * Start a blame.
 *
 * @param filePath The path of the file for which to compute the blame.
 * @param historyController Interface to the history view.
 *
 * @throws IOException Unable to read from the given file.
 * @throws GitAPIException Git related exceptions.
 */
public void doBlame(String filePath, HistoryController historyController) throws IOException, GitAPIException {
    try {
        File file = new File(GitAccess.getInstance().getWorkingCopy(), filePath);
        URL url = file.toURI().toURL();
        // Check if another blame is already active and dispose it.
        dispose(url);
        String ext = Files.getFileExtension(file.getName());
        boolean isProjectExt = "xpr".equals(ext);
        boolean open = PluginWorkspaceProvider.getPluginWorkspace().open(url, // Imposing the text page will open even a DITA Map inside the main editing area.
        EditorPageConstants.PAGE_TEXT, // EXM-44423: open project as XML.
        isProjectExt ? "text/xml" : null);
        if (open) {
            WSEditor editor = PluginWorkspaceProvider.getPluginWorkspace().getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);
            if (editor != null) {
                // Currently we only support text page highlights.
                editor.changePage(EditorPageConstants.PAGE_TEXT);
                BlamePerformer blamePerformer = new BlamePerformer();
                blamePerformer.doit(GitAccess.getInstance().getRepository(), filePath, editor, historyController);
                String key = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().correctURL(url.toExternalForm());
                activeBlames.put(key, blamePerformer);
            } else {
                PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Failed to open editor: " + url);
                LOGGER.error("Editor not found: " + url);
            }
        }
    } catch (NoRepositorySelected e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) WSEditor(ro.sync.exml.workspace.api.editor.WSEditor) File(java.io.File) URL(java.net.URL)

Example 4 with NoRepositorySelected

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

the class RepoUtil method isFileFromRepository.

/**
 * Checks if the file is from the currently loaded Git repository.
 *
 * @param editorLocation File location.
 *
 * @return <code>true</code> if the file is from the currently loaded Git repository.
 * <code>false</code> otherwise.
 */
public static boolean isFileFromRepository(URL editorLocation) {
    boolean toRet = false;
    File locateFile = null;
    if ("file".equals(editorLocation.getProtocol())) {
        locateFile = PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().locateFile(editorLocation);
        if (locateFile != null) {
            String fileInWorkPath = locateFile.toString();
            fileInWorkPath = FileUtil.rewriteSeparator(fileInWorkPath);
            try {
                String selectedRepositoryPath = GitAccess.getInstance().getWorkingCopy().getAbsolutePath();
                selectedRepositoryPath = FileUtil.rewriteSeparator(selectedRepositoryPath);
                toRet = fileInWorkPath.startsWith(selectedRepositoryPath);
            } catch (NoRepositorySelected ex) {
            // No repository loaded.
            }
        }
    }
    return toRet;
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) File(java.io.File)

Example 5 with NoRepositorySelected

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

the class DiffPresenter method showConflictDiff.

/**
 * Presents a 3-way diff.
 *
 * @param file The file for which to show the Diff.
 * @param gitController Git controller.
 */
private static void showConflictDiff(FileStatus file, GitControllerBase gitController) {
    try {
        URL base = GitRevisionURLHandler.encodeURL(VersionIdentifier.BASE, file.getFileLocation());
        URL left = null;
        URL right = null;
        // builds the URL for the files depending if we are in rebasing state or not
        RepositoryState repositoryState = GitAccess.getInstance().getRepository().getRepositoryState();
        boolean isRebase = repositoryState.equals(RepositoryState.REBASING) || repositoryState.equals(RepositoryState.REBASING_INTERACTIVE) || repositoryState.equals(RepositoryState.REBASING_MERGE) || repositoryState.equals(RepositoryState.REBASING_REBASING);
        if (isRebase) {
            // An unfinished rebased.
            left = GitRevisionURLHandler.encodeURL(VersionIdentifier.MINE_RESOLVED, file.getFileLocation());
            right = GitRevisionURLHandler.encodeURL(VersionIdentifier.MINE_ORIGINAL, file.getFileLocation());
        } else {
            left = GitRevisionURLHandler.encodeURL(VersionIdentifier.MINE, file.getFileLocation());
            right = GitRevisionURLHandler.encodeURL(VersionIdentifier.THEIRS, file.getFileLocation());
        }
        String selectedRepository = OptionsManager.getInstance().getSelectedRepository();
        final File localCopy = new File(selectedRepository, file.getFileLocation());
        // time stamp used for detecting if the file was changed in the diff view
        final long diffStartedTimeStamp = localCopy.lastModified();
        Optional<JFrame> diffFrame = showDiffFrame(left, right, base, file.getFileLocation());
        // checks if the file in conflict has been resolved or not after the diff
        // view was closed
        diffFrame.ifPresent(d -> d.addComponentListener(new ComponentAdapter() {

            @Override
            public void componentHidden(ComponentEvent e) {
                long diffClosedTimeStamp = localCopy.lastModified();
                if (diffClosedTimeStamp == diffStartedTimeStamp) {
                    String message = isRebase ? TRANSLATOR.getTranslation(Tags.KEEP_RESOLVED_VERSION_FOR_REBASE_CONFLICT) : TRANSLATOR.getTranslation(Tags.CHECK_IF_CONFLICT_RESOLVED);
                    int response = FileStatusDialog.showWarningMessageWithConfirmation(TRANSLATOR.getTranslation(Tags.CHECK_IF_CONFLICT_RESOLVED_TITLE), message, TRANSLATOR.getTranslation(Tags.RESOLVE_ANYWAY), TRANSLATOR.getTranslation(Tags.KEEP_CONFLICT));
                    if (response == OKCancelDialog.RESULT_OK) {
                        gitController.asyncResolveUsingMine(Collections.singletonList(file));
                    }
                } else {
                    // Instead of requesting the file status again, we just mark it as modified.
                    file.setChangeType(GitChangeType.MODIFIED);
                    gitController.asyncAddToIndex(Collections.singletonList(file));
                }
                d.removeComponentListener(this);
            }
        }));
    } catch (MalformedURLException | NoRepositorySelected e1) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(e1.getMessage(), e1);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) RepositoryState(org.eclipse.jgit.lib.RepositoryState) URL(java.net.URL) NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) JFrame(javax.swing.JFrame) ComponentEvent(java.awt.event.ComponentEvent) File(java.io.File) ComponentAdapter(java.awt.event.ComponentAdapter)

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