Search in sources :

Example 21 with GitController

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

the class GitCheckoutConflictTest method testSwitchBranchWhenRepoInConflict_checkoutConflict_1.

/**
 * <p><b>Description:</b> try to switch branch from Git Branch Manager when repo is in conflict state.
 * The branch switch also generates a checkout conflict.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testSwitchBranchWhenRepoInConflict_checkoutConflict_1() 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 branch
    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());
    GitControllerBase mock = new GitController();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
    branchManagementPanel.refreshBranches();
    sleep(500);
    BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
    // Simulate branch checkout from Git Branch Manager view
    GitTreeNode node = new GitTreeNode(new TreePath(new String[] { "refs", "heads", "new_branch" }));
    node.setUserObject("refs/heads/new_branch");
    List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(node);
    for (AbstractAction abstractAction : actionsForNode) {
        if (abstractAction.getValue(AbstractAction.NAME).equals(Tags.CHECKOUT)) {
            SwingUtilities.invokeLater(() -> abstractAction.actionPerformed(null));
            break;
        }
    }
    sleep(500);
    assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
    assertEquals("Branch_switch_when_repo_in_conflict_error_msg", errMsg[0]);
}
Also used : BranchTreeMenuActionsProvider(com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) TreePath(javax.swing.tree.TreePath) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) BranchManagementPanel(com.oxygenxml.git.view.branches.BranchManagementPanel) AbstractAction(javax.swing.AbstractAction) Test(org.junit.Test)

Example 22 with GitController

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

the class GitPullCasesTest method testPullWithConflicts_Merge.

/**
 * Pull (merge). There are uncommitted changes that overlap with the incoming changes.
 *
 * @throws Exception
 */
@Test
public void testPullWithConflicts_Merge() throws Exception {
    String local1Repository = "target/test-resources/GitPullCasesTest/testPullWithConflicts-local";
    String local2Repository = "target/test-resources/GitPullCasesTest/testPullWithConflicts-local-second";
    String remoteRepository = "target/test-resources/GitPullCasesTest/testPullWithConflicts-remote";
    Repository local1Repo = createRepository(local1Repository);
    Repository local2Repos = createRepository(local2Repository);
    Repository remoteRepo = createRepository(remoteRepository);
    bindLocalToRemote(local1Repo, remoteRepo);
    bindLocalToRemote(local2Repos, remoteRepo);
    // ----------------
    // LOCAL 1
    // ----------------
    GitAccess instance = GitAccess.getInstance();
    instance.setRepositorySynchronously(local1Repository);
    // Create a file in the remote.
    File remoteParent = new File(local1Repository);
    remoteParent.mkdirs();
    File local1File = new File(local1Repository, "test.txt");
    setFileContent(local1File, "original");
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Primul");
    push("", "");
    // ----------------
    // LOCAL 2
    // ----------------
    instance.setRepositorySynchronously(local2Repository);
    PullResponse pull = pull("", "", PullType.MERGE_FF, false);
    assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
    File local2File = new File(new File(local2Repository), "test.txt");
    assertEquals("original", TestUtil.read(local2File.toURI().toURL()));
    setFileContent(local2File, "changed in local 2");
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Primul");
    push("", "");
    // ----------------
    // LOCAL 1
    // ----------------
    instance.setRepositorySynchronously(local1Repository);
    setFileContent(local1File, "changed in local 1");
    final StringBuilder pullWithConflicts = new StringBuilder();
    final List<String> filesWithChanges = new ArrayList<>();
    GitController pc = new GitController(GitAccess.getInstance()) {

        @Override
        protected void showPullFailedBecauseOfCertainChanges(List<String> files, String message) {
            filesWithChanges.addAll(files);
        }

        @Override
        protected void showPullSuccessfulWithConflicts(PullResponse response) {
            pullWithConflicts.append(response);
        }
    };
    final StringBuilder b = new StringBuilder();
    TestUtil.collectPushPullEvents(pc, b);
    pc.pull().get();
    assertEquals("[test.txt]", filesWithChanges.toString());
    assertEquals("Status: STARTED, message: Pull_In_Progress\n" + "Status: FINISHED, message: \n" + "", b.toString());
    filesWithChanges.clear();
    // Commit.
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Another");
    push("", "");
    pc.pull().get();
    assertTrue(filesWithChanges.isEmpty());
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflicts.toString());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) GitController(com.oxygenxml.git.view.event.GitController) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 23 with GitController

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

the class GitPullCasesTest method testPullWithConflicts_Rebase.

/**
 * Pull (rebase). There are uncommitted changes that overlap with the incoming changes.
 *
 * @throws Exception
 */
@Test
public void testPullWithConflicts_Rebase() throws Exception {
    String local1Repository = "target/test-resources/GitPullCasesTest/testPullWithConflicts-rebase-local";
    String local2Repository = "target/test-resources/GitPullCasesTest/testPullWithConflicts-rebase-local-second";
    String remoteRepository = "target/test-resources/GitPullCasesTest/testPullWithConflicts-rebase-remote";
    Repository local1Repo = createRepository(local1Repository);
    Repository local2Repos = createRepository(local2Repository);
    Repository remoteRepo = createRepository(remoteRepository);
    bindLocalToRemote(local1Repo, remoteRepo);
    bindLocalToRemote(local2Repos, remoteRepo);
    // ----------------
    // LOCAL 1
    // ----------------
    GitAccess instance = GitAccess.getInstance();
    instance.setRepositorySynchronously(local1Repository);
    // Create a file in the remote.
    File remoteParent = new File(local1Repository);
    remoteParent.mkdirs();
    File local1File = new File(local1Repository, "test.txt");
    setFileContent(local1File, "original");
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Primul");
    push("", "");
    // ----------------
    // LOCAL 2
    // ----------------
    instance.setRepositorySynchronously(local2Repository);
    PullResponse pull = pull("", "", PullType.MERGE_FF, false);
    assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
    File local2File = new File(new File(local2Repository), "test.txt");
    assertEquals("original", TestUtil.read(local2File.toURI().toURL()));
    setFileContent(local2File, "changed in local 2");
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Al doilea");
    push("", "");
    // ----------------
    // LOCAL 1
    // ----------------
    instance.setRepositorySynchronously(local1Repository);
    setFileContent(local1File, "changed in local 1");
    final StringBuilder pullWithConflicts = new StringBuilder();
    final List<String> filesWithChanges = new ArrayList<>();
    GitController pc = new GitController() {

        @Override
        protected void showPullFailedBecauseOfCertainChanges(List<String> files, String message) {
            filesWithChanges.addAll(files);
        }

        @Override
        protected void showPullSuccessfulWithConflicts(PullResponse response) {
            pullWithConflicts.append(response);
        }
    };
    final StringBuilder b = new StringBuilder();
    TestUtil.collectPushPullEvents(pc, b);
    pc.pull(PullType.REBASE).get();
    assertEquals("[test.txt]", filesWithChanges.toString());
    assertEquals("Status: STARTED, message: Pull_In_Progress\n" + "Status: FINISHED, message: \n" + "", b.toString());
    filesWithChanges.clear();
    // Commit.
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Another");
    push("", "");
    pc.pull(PullType.REBASE).get();
    assertTrue(filesWithChanges.isEmpty());
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflicts.toString());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) GitController(com.oxygenxml.git.view.event.GitController) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 24 with GitController

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

the class GitPullCasesTest method testPullWithConflicts_EXM_41770.

/**
 * <p><b>Description:</b> A file is modified both in the remote and the local repository. The same file
 * is changed inside the working copy.</p>
 * <p><b>Bug ID:</b> EXM-41770</p>
 *
 * @author alex_jitianu
 *
 * @throws Exception If it fails.
 */
@Test
public void testPullWithConflicts_EXM_41770() throws Exception {
    String local1Repository = "target/test-resources/GitPullCasesTest/testPullWithConflicts_EXM_41770-local";
    String local2Repository = "target/test-resources/GitPullCasesTest/testPullWithConflicts_EXM_41770-local-second";
    String remoteRepository = "target/test-resources/GitPullCasesTest/testPullWithConflicts_EXM_41770-remote";
    Repository local1Repo = createRepository(local1Repository);
    Repository local2Repos = createRepository(local2Repository);
    Repository remoteRepo = createRepository(remoteRepository);
    bindLocalToRemote(local1Repo, remoteRepo);
    bindLocalToRemote(local2Repos, remoteRepo);
    // ----------------
    // LOCAL 1
    // ----------------
    GitAccess instance = GitAccess.getInstance();
    instance.setRepositorySynchronously(local1Repository);
    // Create a file in the remote.
    File remoteParent = new File(local1Repository);
    remoteParent.mkdirs();
    File local1File = new File(local1Repository, "test.txt");
    setFileContent(local1File, "original");
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Primul");
    push("", "");
    // Second change.
    setFileContent(local1File, "local1-changed");
    instance.commit("Al doilea");
    // ----------------
    // LOCAL 2
    // ----------------
    instance.setRepositorySynchronously(local2Repository);
    PullResponse pull = pull("", "", PullType.MERGE_FF, false);
    assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
    File local2File = new File(new File(local2Repository), "test.txt");
    assertEquals("original", TestUtil.read(local2File.toURI().toURL()));
    setFileContent(local2File, "changed in local 2");
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Primul");
    push("", "");
    // ----------------
    // LOCAL 1
    // ----------------
    instance.setRepositorySynchronously(local1Repository);
    setFileContent(local1File, "changed in local 1");
    final StringBuilder pullWithConflicts = new StringBuilder();
    final List<String> filesWithChanges = new ArrayList<>();
    GitController pc = new GitController(GitAccess.getInstance()) {

        @Override
        protected void showPullFailedBecauseOfCertainChanges(List<String> files, String message) {
            filesWithChanges.addAll(files);
        }

        @Override
        protected void showPullSuccessfulWithConflicts(PullResponse response) {
            pullWithConflicts.append(response);
        }
    };
    final StringBuilder b = new StringBuilder();
    TestUtil.collectPushPullEvents(pc, b);
    pc.pull().get();
    assertEquals("[test.txt]", filesWithChanges.toString());
    assertEquals("Status: STARTED, message: Pull_In_Progress\n" + "Status: FINISHED, message: \n" + "", b.toString());
    filesWithChanges.clear();
    // Commit.
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Another");
    push("", "");
    pc.pull().get();
    assertTrue(filesWithChanges.isEmpty());
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflicts.toString());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) GitController(com.oxygenxml.git.view.event.GitController) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 25 with GitController

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

the class GitPullCasesTest method testPullWithRebase_UncommittedNewFileConflict.

@Test
public void testPullWithRebase_UncommittedNewFileConflict() throws Exception {
    String local1Repository = "target/test-resources/GitPullCasesTest/testPullWithRebase_UncommittedNewFileConflict-local";
    String local2Repository = "target/test-resources/GitPullCasesTest/testPullWithRebase_UncommittedNewFileConflict-local-second";
    String remoteRepository = "target/test-resources/GitPullCasesTest/testPullWithRebase_UncommittedNewFileConflict-remote";
    Repository local1Repo = createRepository(local1Repository);
    Repository local2Repos = createRepository(local2Repository);
    Repository remoteRepo = createRepository(remoteRepository);
    bindLocalToRemote(local1Repo, remoteRepo);
    bindLocalToRemote(local2Repos, remoteRepo);
    // ----------------
    // LOCAL 1
    // ----------------
    GitAccess instance = GitAccess.getInstance();
    instance.setRepositorySynchronously(local1Repository);
    // Create a file in the remote.
    File remoteParent = new File(local1Repository);
    remoteParent.mkdirs();
    File local1File = new File(local1Repository, "test.txt");
    setFileContent(local1File, "original");
    instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    instance.commit("Primul");
    push("", "");
    // ----------------
    // LOCAL 2
    // ----------------
    instance.setRepositorySynchronously(local2Repository);
    File local2File = new File(new File(local2Repository), "test.txt");
    local2File.createNewFile();
    final StringBuilder pullWithConflicts = new StringBuilder();
    final List<String> filesWithChanges = new ArrayList<>();
    final List<String> messages = new ArrayList<>();
    GitController pc = new GitController() {

        @Override
        protected void showPullFailedBecauseOfCertainChanges(List<String> files, String message) {
            filesWithChanges.addAll(files);
            messages.add(message);
        }

        @Override
        protected void showPullSuccessfulWithConflicts(PullResponse response) {
            pullWithConflicts.append(response);
        }
    };
    final StringBuilder b = new StringBuilder();
    TestUtil.collectPushPullEvents(pc, b);
    pc.pull(PullType.REBASE).get();
    assertEquals("[Pull_failed_because_conflicting_paths] FOR [test.txt]", messages + " FOR " + filesWithChanges);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) GitController(com.oxygenxml.git.view.event.GitController) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) 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