Search in sources :

Example 1 with BranchSelectionCombo

use of com.oxygenxml.git.view.staging.BranchSelectionCombo 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 BranchSelectionCombo

use of com.oxygenxml.git.view.staging.BranchSelectionCombo 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 BranchSelectionCombo

use of com.oxygenxml.git.view.staging.BranchSelectionCombo in project oxygen-git-client-addon by oxygenxml.

the class GitCheckoutConflictTest method testSwitchBranchFromGitBranchManager_checkoutConflict_2.

/**
 * <p><b>Description:</b> try to switch branch from Git Staging.
 * The branch witch generates a checkout conflict.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testSwitchBranchFromGitBranchManager_checkoutConflict_2() throws Exception {
    // Push from first repo
    gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
    writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "hellllo");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("file test added");
    push("", "");
    // Change file on the new branch
    gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
    gitAccess.setBranch("new_branch");
    writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "altfel");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("commit 2");
    // move to main branch
    gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "new content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    GitControllerBase gitCtrl = new GitController();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(gitCtrl);
    branchManagementPanel.refreshBranches();
    flushAWT();
    BranchSelectionCombo branchesCombo = new BranchSelectionCombo((GitController) gitCtrl);
    branchesCombo.refresh();
    SwingUtilities.invokeLater(() -> branchesCombo.setSelectedIndex(1));
    flushAWT();
    Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    JButton yesButton = TestUtil.findButton(focusedWindow, translator.getTranslation(Tags.MOVE_CHANGES));
    yesButton.doClick();
    sleep(1000);
    assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
    assertEquals("Branch_switch_checkout_conflict_error_msg", errMsg[0]);
}
Also used : Window(java.awt.Window) FileStatus(com.oxygenxml.git.service.entities.FileStatus) BranchSelectionCombo(com.oxygenxml.git.view.staging.BranchSelectionCombo) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) BranchManagementPanel(com.oxygenxml.git.view.branches.BranchManagementPanel) Test(org.junit.Test)

Example 4 with BranchSelectionCombo

use of com.oxygenxml.git.view.staging.BranchSelectionCombo in project oxygen-git-client-addon by oxygenxml.

the class GitCheckoutConflictTest method testSwitchBranchWhenRepoInConflict_checkoutConflict_2.

/**
 * <p><b>Description:</b> try to switch branch from Git Staging when repo is in conflict state.
 * The branch witch also generates a checkout conflict.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testSwitchBranchWhenRepoInConflict_checkoutConflict_2() throws Exception {
    // Push from first repo
    gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
    writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "hellllo");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("file test added");
    push("", "");
    // Commit from second repo
    gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
    File file = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
    file.createNewFile();
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("conflict");
    // Change file on the new branch
    gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
    gitAccess.setBranch("new_branch");
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "altfel");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("commit on ew branch");
    // move to main
    gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    // Pull to create conflict
    PullResponse pullResp = pull("", "", PullType.MERGE_FF, false);
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullResp.toString());
    // Simulate branch checkout from Git Staging
    GitController gitController = new GitController(gitAccess);
    BranchSelectionCombo branchesCombo = new BranchSelectionCombo(gitController);
    branchesCombo.refresh();
    SwingUtilities.invokeLater(() -> branchesCombo.setSelectedIndex(1));
    flushAWT();
    assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
    assertEquals("Branch_switch_when_repo_in_conflict_error_msg", errMsg[0]);
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) BranchSelectionCombo(com.oxygenxml.git.view.staging.BranchSelectionCombo) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) Test(org.junit.Test)

Example 5 with BranchSelectionCombo

use of com.oxygenxml.git.view.staging.BranchSelectionCombo in project oxygen-git-client-addon by oxygenxml.

the class GitCheckoutConflictTest method testSwitchBranchWhenRepoInConflict_succeed_1.

/**
 * <p><b>Description:</b> try to switch branch from Git Staging when repo is in conflict state.
 * This should succeed.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testSwitchBranchWhenRepoInConflict_succeed_1() throws Exception {
    // Push test.txt from first repo
    gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
    writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "hellllo");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("file test added");
    push("", "");
    // Commit test.txt from second repo
    gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
    File file = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
    file.createNewFile();
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("conflict");
    // Change file.txt file on the new branch
    gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
    gitAccess.setBranch("new_branch");
    ;
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/file.txt"), "altfel");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "file.txt"));
    gitAccess.commit("commit on nnew branch");
    // move to main
    gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    // change file.txt to create checkout conflict
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/file.txt"), "new changes");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "file.txt"));
    // Pull to create conflict o text.txt
    PullResponse pullResp = pull("", "", PullType.MERGE_FF, false);
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullResp.toString());
    // Simulate branch checkout from Git Staging
    GitController gitController = new GitController(gitAccess);
    BranchSelectionCombo branchesCombo = new BranchSelectionCombo(gitController);
    branchesCombo.refresh();
    SwingUtilities.invokeLater(() -> branchesCombo.setSelectedIndex(1));
    flushAWT();
    assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
    assertEquals("Branch_switch_when_repo_in_conflict_error_msg", errMsg[0]);
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) BranchSelectionCombo(com.oxygenxml.git.view.staging.BranchSelectionCombo) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) Test(org.junit.Test)

Aggregations

FileStatus (com.oxygenxml.git.service.entities.FileStatus)5 GitController (com.oxygenxml.git.view.event.GitController)5 BranchSelectionCombo (com.oxygenxml.git.view.staging.BranchSelectionCombo)5 File (java.io.File)5 JButton (javax.swing.JButton)3 Test (org.junit.Test)3 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)2 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)2 JDialog (javax.swing.JDialog)2 JFrame (javax.swing.JFrame)2 BranchManagementPanel (com.oxygenxml.git.view.branches.BranchManagementPanel)1 StashChangesDialog (com.oxygenxml.git.view.stash.StashChangesDialog)1 Window (java.awt.Window)1