Search in sources :

Example 1 with CurrentBranchRemotesDialog

use of com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog in project oxygen-git-client-addon by oxygenxml.

the class RemoteVisualTests method testTrackRemoteBranch.

/**
 * <p><b>Description:</b> Tests the "Track remote branch" action from remote button of git staging toolbar.</p>
 * <p><b>Bug ID:</b> EXM-40858</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testTrackRemoteBranch() throws Exception {
    final String remoteRepo2Branch = "branch_remote_repo_2";
    final String remote2 = "remote2_name";
    // Creates the remote repository.
    createRepository(REMOTE_REPO2);
    Repository remoteRepository = gitAccess.getRepository();
    addRemote(localRepository, remoteRepository, remote2);
    gitAccess.createBranch(remoteRepo2Branch);
    File file = new File(REMOTE_REPO2, "remote2.txt");
    file.createNewFile();
    setFileContent(file, "remote2content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote2.txt"));
    gitAccess.commit("First remote2 commit.");
    // Make the first commit for the local repository
    file = new File(LOCAL_REPO, "local.txt");
    file.createNewFile();
    setFileContent(file, "local content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
    gitAccess.commit("First local commit.");
    // Make the first commit for the remote repository and create a branch for it.
    gitAccess.setRepositorySynchronously(REMOTE_REPO);
    file = new File(REMOTE_REPO, "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    // Switch back to local repo and create local branch
    gitAccess.setRepositorySynchronously(LOCAL_REPO);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        refreshSupport.call();
        flushAWT();
        SwingUtilities.invokeLater(() -> gitActionsManager.getTrackRemoteBranchAction().actionPerformed(null));
        flushAWT();
        CurrentBranchRemotesDialog[] trackRemoteDialog = new CurrentBranchRemotesDialog[1];
        trackRemoteDialog[0] = (CurrentBranchRemotesDialog) findDialog(Tags.CONFIGURE_REMOTE_FOR_BRANCH);
        assertNotNull(trackRemoteDialog);
        flushAWT();
        JComboBox<RemoteBranchItem> remoteBranches = trackRemoteDialog[0].getRemoteBranchItems();
        assertNotNull(remoteBranches);
        assertEquals(2, remoteBranches.getItemCount());
        assertEquals("origin", gitAccess.getRemoteFromCurrentBranch());
        RemoteBranchItem currentSelected = (RemoteBranchItem) remoteBranches.getSelectedItem();
        assertEquals("origin/main", currentSelected.toString());
        remoteBranches.setSelectedIndex(1);
        currentSelected = (RemoteBranchItem) remoteBranches.getSelectedItem();
        assertEquals("remote2_name/main", currentSelected.toString());
        flushAWT();
        sleep(500);
        SwingUtilities.invokeLater(() -> trackRemoteDialog[0].getOkButton().doClick());
        // Test if the config file is updated after user confirmation.
        SwingUtilities.invokeLater(() -> gitActionsManager.getTrackRemoteBranchAction().actionPerformed(null));
        flushAWT();
        trackRemoteDialog[0] = (CurrentBranchRemotesDialog) findDialog(Tags.CONFIGURE_REMOTE_FOR_BRANCH);
        assertNotNull(trackRemoteDialog);
        flushAWT();
        remoteBranches = trackRemoteDialog[0].getRemoteBranchItems();
        assertNotNull(remoteBranches);
        assertEquals(remote2, gitAccess.getRemoteFromCurrentBranch());
        currentSelected = (RemoteBranchItem) remoteBranches.getSelectedItem();
        assertEquals("remote2_name/main", currentSelected.toString());
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : CurrentBranchRemotesDialog(com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog) Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JFrame(javax.swing.JFrame) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) RemoteBranchItem(com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog.RemoteBranchItem) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 2 with CurrentBranchRemotesDialog

use of com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog in project oxygen-git-client-addon by oxygenxml.

the class SetRemoteAction method setRemote.

/**
 * Tries to set the remote for current branch.
 */
private void setRemote() {
    CurrentBranchRemotesDialog dialog = new CurrentBranchRemotesDialog();
    if (dialog.getStatusResult() == CurrentBranchRemotesDialog.STATUS_REMOTE_NOT_EXISTS) {
        OKCancelDialog addRemoteDialog = new AddRemoteDialog();
        addRemoteDialog.setVisible(true);
        if (addRemoteDialog.getResult() == OKCancelDialog.RESULT_OK) {
            setRemote();
        }
    } else if (dialog.getStatusResult() == CurrentBranchRemotesDialog.STATUS_BRANCHES_NOT_EXIST) {
        FileStatusDialog.showErrorMessage(TRANSLATOR.getTranslation(Tags.CONFIGURE_REMOTE_FOR_BRANCH), null, TRANSLATOR.getTranslation(Tags.NO_BRANCHES_FOUNDED));
    }
}
Also used : CurrentBranchRemotesDialog(com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog) OKCancelDialog(ro.sync.exml.workspace.api.standalone.ui.OKCancelDialog) AddRemoteDialog(com.oxygenxml.git.view.dialog.AddRemoteDialog)

Aggregations

CurrentBranchRemotesDialog (com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog)2 FileStatus (com.oxygenxml.git.service.entities.FileStatus)1 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)1 AddRemoteDialog (com.oxygenxml.git.view.dialog.AddRemoteDialog)1 GitController (com.oxygenxml.git.view.event.GitController)1 RemoteBranchItem (com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog.RemoteBranchItem)1 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)1 File (java.io.File)1 JFrame (javax.swing.JFrame)1 Repository (org.eclipse.jgit.lib.Repository)1 OKCancelDialog (ro.sync.exml.workspace.api.standalone.ui.OKCancelDialog)1