Search in sources :

Example 1 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class BranchSelectionComboTest method testKeepCurrentBranchSelectedWhenSwitchFails.

/**
 * <p><b>Description:</b> when trying to switch to another branch from the branches menu
 * and the checkout fails, keep the previous branch selected.</p>
 * <p><b>Bug ID:</b> EXM-46826</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testKeepCurrentBranchSelectedWhenSwitchFails() throws Exception {
    File testDir = new File(String.format("target/test-resources/ToolbarPanelTest/%s", this.getName()));
    String local = String.format("target/test-resources/ToolbarPanelTest/%s/localRepository", this.getName());
    String remote = String.format("target/test-resources/ToolbarPanelTest/%s/remoteRepository", this.getName());
    String LOCAL_BRANCH = "LocalBranch";
    // Creates the remote repository.
    createRepo(remote, local);
    // Make the first commit for the local repository
    File file = new File(local, "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);
    file = new File(remote, "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);
    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);
        JComboBox<String> wcCombo = stagingPanel.getWorkingCopySelectionPanel().getWorkingCopyCombo();
        String wcPath = new File(local).getAbsolutePath();
        wcCombo.addItem(wcPath);
        wcCombo.setSelectedItem(wcPath);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        refreshSupport.call();
        flushAWT();
        // Commit a change
        file = new File(local, "local.txt");
        setFileContent(file, "new 2");
        gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
        gitAccess.commit("First remote commit.");
        flushAWT();
        // Create local change
        setFileContent(file, "new 3");
        refreshSupport.call();
        flushAWT();
        // Try to switch to another branch
        BranchSelectionCombo branchesCombo = stagingPanel.getBranchesCombo();
        branchesCombo.refresh();
        String currentBranch = (String) branchesCombo.getSelectedItem();
        assertEquals("main", currentBranch);
        // select the "Local Branch" (aka the broken one)
        branchesCombo.setSelectedIndex(0);
        // wait for swith dialog to appear
        JDialog switchBranchDialog = TestUtil.waitForDialog(translator.getTranslation(Tags.SWITCH_BRANCH), this);
        JButton yesButton = TestUtil.findButton(switchBranchDialog, translator.getTranslation(Tags.MOVE_CHANGES));
        yesButton.doClick();
        flushAWT();
        String currentBranchAfterSwitchFailed = (String) branchesCombo.getSelectedItem();
        assertEquals("main", currentBranchAfterSwitchFailed);
    } finally {
        frame.setVisible(false);
        frame.dispose();
        FileSystemUtil.deleteRecursivelly(testDir);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) BranchSelectionCombo(com.oxygenxml.git.view.staging.BranchSelectionCombo) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) JDialog(javax.swing.JDialog) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 2 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class BranchSelectionComboTest method testCanStashChangesIfSwitchBranchFailsBecauseUncommitedFiles.

/**
 * <p><b>Description:</b> when trying to switch to another branch from the branches menu
 * and the checkout fails, tests the dialog</p>
 * <p><b>Bug ID:</b> EXM-48502</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testCanStashChangesIfSwitchBranchFailsBecauseUncommitedFiles() throws Exception {
    File testDir = new File(String.format("target/test-resources/ToolbarPanelTest/%s", this.getName()));
    String local = String.format("target/test-resources/ToolbarPanelTest/%s/localRepository", this.getName());
    String remote = String.format("target/test-resources/ToolbarPanelTest/%s/remoteRepository", this.getName());
    String LOCAL_BRANCH = "LocalBranch";
    // Creates the remote repository.
    createRepo(remote, local);
    // Make the first commit for the local repository
    File file = new File(local, "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);
    file = new File(remote, "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);
    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);
        JComboBox<String> wcCombo = stagingPanel.getWorkingCopySelectionPanel().getWorkingCopyCombo();
        String wcPath = new File(local).getAbsolutePath();
        wcCombo.addItem(wcPath);
        wcCombo.setSelectedItem(wcPath);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        refreshSupport.call();
        flushAWT();
        // Commit a change
        file = new File(local, "local.txt");
        setFileContent(file, "new 2");
        gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
        gitAccess.commit("First remote commit.");
        flushAWT();
        // Create local change
        setFileContent(file, "new 3");
        refreshSupport.call();
        flushAWT();
        // Try to switch to another branch
        BranchSelectionCombo branchesCombo = stagingPanel.getBranchesCombo();
        branchesCombo.refresh();
        flushAWT();
        String currentBranch = (String) branchesCombo.getSelectedItem();
        assertEquals("main", currentBranch);
        // select other branch
        branchesCombo.setSelectedIndex(0);
        JDialog switchBranchDialog = TestUtil.waitForDialog(translator.getTranslation(Tags.SWITCH_BRANCH), this);
        JButton stashButton = TestUtil.findButton(switchBranchDialog, Tags.STASH_CHANGES);
        stashButton.doClick();
        flushAWT();
        StashChangesDialog stashChangesDialog = (StashChangesDialog) findDialog(Tags.STASH_CHANGES);
        assertNotNull(stashChangesDialog);
        stashChangesDialog.setVisible(false);
        stashChangesDialog.dispose();
    } finally {
        frame.setVisible(false);
        frame.dispose();
        FileSystemUtil.deleteRecursivelly(testDir);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) BranchSelectionCombo(com.oxygenxml.git.view.staging.BranchSelectionCombo) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) StashChangesDialog(com.oxygenxml.git.view.stash.StashChangesDialog) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) JDialog(javax.swing.JDialog) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 3 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class FlatView2Test method testAPullCannotLockRef.

/**
 * <p><b>Description:</b> lock fail test.</p>
 * <p><b>Bug ID:</b> EXM-42867</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception If it fails.
 */
@Test
public void testAPullCannotLockRef() throws Exception {
    PluginWorkspace pluginWorkspaceMock = PluginWorkspaceProvider.getPluginWorkspace();
    final boolean[] showErrorMessageCalled = new boolean[] { false };
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            showErrorMessageCalled[0] = true;
            return null;
        }
    }).when(pluginWorkspaceMock).showErrorMessage(Mockito.anyString());
    PluginWorkspaceProvider.setPluginWorkspace(pluginWorkspaceMock);
    String localTestRepository = "target/test-resources/testStageUnstage_ModifiedFile_local_pullCannotLock";
    String remoteTestRepository = "target/test-resources/testStageUnstage_ModifiedFile_remote_pullCannotLock";
    // Create repositories
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo = createRepository(localTestRepository);
    bindLocalToRemote(localRepo, remoteRepo);
    sleep(700);
    // Create a new file and push it.
    String fileName = "test.txt";
    File file = commitNewFile(localTestRepository, fileName, "content");
    PushResponse push = push("", "");
    assertEquals("status: OK message null", push.toString());
    // Create lock files
    String repoDir = GitAccess.getInstance().getRepository().getDirectory().getAbsolutePath();
    Ref ref = GitAccess.getInstance().getRemoteBrachListForCurrentRepo().get(0);
    File lockFile = new File(repoDir, ref.getName() + ".lock");
    boolean createNewFile = lockFile.createNewFile();
    assertTrue("Unnable to create lock file " + lockFile.getAbsolutePath(), createNewFile);
    setFileContent(lockFile, GitAccess.getInstance().getLastLocalCommitInRepo().getName());
    // Commit a new version of the file.
    setFileContent(file, "modified");
    GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, fileName));
    GitAccess.getInstance().commit("modified");
    push("", "");
    assertEquals("status: OK message null", push.toString());
    // Pull should throw "Lock failed" error
    PullResponse pullResponse = pull("", "", PullType.MERGE_FF, false);
    assertEquals(PullStatus.LOCK_FAILED, pullResponse.getStatus());
    assertTrue(showErrorMessageCalled[0]);
    Future<?> execute = ((GitController) stagingPanel.getGitController()).pull();
    execute.get();
    flushAWT();
    assertEquals("Lock_failed", stagingPanel.getCommitPanel().getStatusLabel().getText());
}
Also used : PluginWorkspace(ro.sync.exml.workspace.api.PluginWorkspace) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitController(com.oxygenxml.git.view.event.GitController) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PullResponse(com.oxygenxml.git.service.PullResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) PushResponse(com.oxygenxml.git.service.PushResponse) Test(org.junit.Test)

Example 4 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class FlatView2Test method testShowInterruptedRebaseDlg_thenCancel.

/**
 * <p><b>Description:</b> Show interrupted rebase dialog and press cancel.</p>
 * <p><b>Bug ID:</b> EXM-42025</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception If it fails.
 */
@Test
public void testShowInterruptedRebaseDlg_thenCancel() throws Exception {
    String localTestRepository_1 = "target/test-resources/testShowInterruptedRebaseDlg_thenCancel-local-1";
    String localTestRepository_2 = "target/test-resources/testShowInterruptedRebaseDlg_thenCancel-local-2";
    String remoteTestRepository = "target/test-resources/testShowInterruptedRebaseDlg_thenCancel-remote";
    // Create and repositories
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo_1 = createRepository(localTestRepository_1);
    Repository localRepo_2 = createRepository(localTestRepository_2);
    bindLocalToRemote(localRepo_1, remoteRepo);
    bindLocalToRemote(localRepo_2, remoteRepo);
    new File(localTestRepository_1).mkdirs();
    new File(localTestRepository_2).mkdirs();
    // --------------  REPO 1
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
    File firstRepoFile = new File(localTestRepository_1 + "/test.txt");
    firstRepoFile.createNewFile();
    setFileContent(firstRepoFile, "First version");
    GitAccess.getInstance().add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
    GitAccess.getInstance().commit("First commit.");
    push("", "");
    // ----------------- REPO 2
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository_2);
    File secondRepoFile = new File(localTestRepository_2 + "/test.txt");
    refreshSupport.call();
    waitForScheduler();
    assertFalse(secondRepoFile.exists());
    pull("", "", PullType.REBASE, false);
    assertTrue(secondRepoFile.exists());
    // Modify file and commit and push
    setFileContent(secondRepoFile, "Second versions");
    GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    GitAccess.getInstance().commit("Second commit.");
    push("", "");
    // --------------  REPO 1
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
    setFileContent(firstRepoFile, "Third version");
    GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    GitAccess.getInstance().commit("Third commit.");
    // Now pull to generate conflict
    ConflictButtonsPanel rebasePanel = stagingPanel.getConflictButtonsPanel();
    assertFalse(rebasePanel.isShowing());
    flushAWT();
    PullResponse pullResponse = pull("", "", PullType.REBASE, false);
    refreshSupport.call();
    waitForScheduler();
    assertEquals(PullStatus.CONFLICTS, pullResponse.getStatus());
    assertTrue(rebasePanel.isShowing());
    GitController ppc = (GitController) stagingPanel.getGitController();
    ppc.pull(PullType.REBASE);
    flushAWT();
    sleep(300);
    JDialog interruptedRebaseDlg = findDialog(Tags.REBASE_IN_PROGRESS);
    assertNotNull(interruptedRebaseDlg);
    JButton abortBtn = findFirstButton(interruptedRebaseDlg.getRootPane(), Translator.getInstance().getTranslation(Tags.CANCEL));
    abortBtn.doClick();
    flushAWT();
    sleep(1000);
    interruptedRebaseDlg = findDialog(Tags.REBASE_IN_PROGRESS);
    assertNull(interruptedRebaseDlg);
    assertTrue(rebasePanel.isShowing());
    assertTableModels(// Unstaged
    "CONFLICT, test.txt", // Staged
    "");
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) PullResponse(com.oxygenxml.git.service.PullResponse) ConflictButtonsPanel(com.oxygenxml.git.view.staging.ConflictButtonsPanel) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) JDialog(javax.swing.JDialog) Test(org.junit.Test)

Example 5 with GitController

use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.

the class FlatView2Test method testShowInterruptedRebaseDlg_thenContinue.

/**
 * <p><b>Description:</b> Show interrupted rebase dialog and press continue.</p>
 * <p><b>Bug ID:</b> EXM-42025</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception If it fails.
 */
@Test
public void testShowInterruptedRebaseDlg_thenContinue() throws Exception {
    try {
        String localTestRepository_1 = "target/test-resources/testShowInterruptedRebaseDlg_thenContinue-local-1";
        String localTestRepository_2 = "target/test-resources/testShowInterruptedRebaseDlg_thenContinue-local-2";
        String remoteTestRepository = "target/test-resources/testShowInterruptedRebaseDlg_thenContinue-remote";
        // Create and repositories
        Repository remoteRepo = createRepository(remoteTestRepository);
        Repository localRepo_1 = createRepository(localTestRepository_1);
        Repository localRepo_2 = createRepository(localTestRepository_2);
        bindLocalToRemote(localRepo_1, remoteRepo);
        bindLocalToRemote(localRepo_2, remoteRepo);
        new File(localTestRepository_1).mkdirs();
        new File(localTestRepository_2).mkdirs();
        // --------------  REPO 1
        GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
        File firstRepoFile = new File(localTestRepository_1 + "/test.txt");
        firstRepoFile.createNewFile();
        setFileContent(firstRepoFile, "First version");
        GitAccess.getInstance().add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
        GitAccess.getInstance().commit("First commit.");
        push("", "");
        // ----------------- REPO 2
        GitAccess.getInstance().setRepositorySynchronously(localTestRepository_2);
        File secondRepoFile = new File(localTestRepository_2 + "/test.txt");
        refreshSupport.call();
        flushAWT();
        sleep(400);
        assertFalse(secondRepoFile.exists());
        pull("", "", PullType.REBASE, false);
        assertTrue(secondRepoFile.exists());
        // Modify file and commit and push
        setFileContent(secondRepoFile, "Second versions");
        GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
        GitAccess.getInstance().commit("Second commit.");
        push("", "");
        // --------------  REPO 1
        GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
        setFileContent(firstRepoFile, "Third version");
        GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
        GitAccess.getInstance().commit("Third commit.");
        // Now pull to generate conflict
        ConflictButtonsPanel rebasePanel = stagingPanel.getConflictButtonsPanel();
        assertFalse(rebasePanel.isShowing());
        flushAWT();
        PullResponse pullResponse = pull("", "", PullType.REBASE, false);
        refreshSupport.call();
        flushAWT();
        sleep(500);
        assertEquals(PullStatus.CONFLICTS, pullResponse.getStatus());
        assertTrue(rebasePanel.isShowing());
        // Pull again. Rebase in progress dialog is shown
        GitController ppc = (GitController) stagingPanel.getGitController();
        ppc.pull(PullType.REBASE);
        flushAWT();
        sleep(300);
        JDialog rebaseInProgressDlg = findDialog(Tags.REBASE_IN_PROGRESS);
        assertNotNull(rebaseInProgressDlg);
        // Get Cannot_continue_rebase_because_of_conflicts message
        final String[] errMessage = new String[1];
        StandalonePluginWorkspace mockedPluginWS = Mockito.mock(StandalonePluginWorkspace.class);
        Mockito.doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                Object[] arguments = invocation.getArguments();
                if (arguments != null && arguments.length == 1) {
                    errMessage[0] = arguments[0].toString();
                }
                return null;
            }
        }).when(mockedPluginWS).showErrorMessage(Mockito.anyString());
        Mockito.when(mockedPluginWS.getParentFrame()).thenReturn(null);
        PluginWorkspaceProvider.setPluginWorkspace(mockedPluginWS);
        JButton continueBtn = findFirstButton(rebaseInProgressDlg.getRootPane(), Translator.getInstance().getTranslation(Tags.CONTINUE_REBASE));
        continueBtn.doClick();
        waitForScheduler();
        assertEquals("Cannot_continue_rebase_because_of_conflicts", errMessage[0]);
        // Resolve conflict
        GitControllerBase sc = new GitControllerBase(GitAccess.getInstance()) {

            @Override
            protected boolean isUserOKWithResolvingRebaseConflictUsingMineOrTheirs(ConflictResolution cmd) {
                return cmd == ConflictResolution.RESOLVE_USING_MINE;
            }
        };
        sc.asyncResolveUsingMine(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
        flushAWT();
        // Pull again.
        ppc.pull(PullType.REBASE);
        flushAWT();
        sleep(300);
        // Rebase in progress dialog shown
        rebaseInProgressDlg = findDialog(Tags.REBASE_IN_PROGRESS);
        assertNotNull(rebaseInProgressDlg);
        // Now CONTINUE
        continueBtn = findFirstButton(rebaseInProgressDlg.getRootPane(), Translator.getInstance().getTranslation(Tags.CONTINUE_REBASE));
        continueBtn.doClick();
        flushAWT();
        waitForScheduler();
        sleep(1000);
        rebaseInProgressDlg = findDialog(Tags.REBASE_IN_PROGRESS);
        assertNull(rebaseInProgressDlg);
        assertFalse(rebasePanel.isShowing());
        assertTableModels(// Unstaged
        "", // Staged
        "");
    } finally {
        PluginWorkspaceProvider.setPluginWorkspace(null);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) Repository(org.eclipse.jgit.lib.Repository) PullResponse(com.oxygenxml.git.service.PullResponse) ConflictButtonsPanel(com.oxygenxml.git.view.staging.ConflictButtonsPanel) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConflictResolution(com.oxygenxml.git.service.ConflictResolution) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) File(java.io.File) JDialog(javax.swing.JDialog) Test(org.junit.Test)

Aggregations

GitController (com.oxygenxml.git.view.event.GitController)66 File (java.io.File)54 FileStatus (com.oxygenxml.git.service.entities.FileStatus)48 JButton (javax.swing.JButton)29 Test (org.junit.Test)28 JDialog (javax.swing.JDialog)24 Repository (org.eclipse.jgit.lib.Repository)21 AbstractAction (javax.swing.AbstractAction)19 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)18 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)18 JFrame (javax.swing.JFrame)15 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)14 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)13 ArrayList (java.util.ArrayList)12 List (java.util.List)12 JTextField (javax.swing.JTextField)10 BranchManagementPanel (com.oxygenxml.git.view.branches.BranchManagementPanel)8 BranchTreeMenuActionsProvider (com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider)7 ToolbarPanel (com.oxygenxml.git.view.staging.ToolbarPanel)7 JCheckBox (javax.swing.JCheckBox)7