use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflict2Test method testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_1.
/**
* <p><b>Description:</b> try to switch to a newly created branch from Git Branch Manager
* when repo is in conflict state.
* The branch checkout also generates a checkout conflict.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCheckoutNewBranchWhenRepoInConflict_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(translator.getTranslation(Tags.CREATE_BRANCH) + "...")) {
SwingUtilities.invokeLater(() -> {
abstractAction.actionPerformed(null);
});
flushAWT();
JDialog createBranchDialog = findDialog(translator.getTranslation(Tags.CREATE_BRANCH));
JCheckBox checkoutBranchCheckBox = findCheckBox(createBranchDialog, Tags.CHECKOUT_BRANCH);
assertNotNull(checkoutBranchCheckBox);
checkoutBranchCheckBox.setSelected(true);
flushAWT();
JTextField branchNameTextField = findComponentNearJLabel(createBranchDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
branchNameTextField.setText("a_new_day");
JButton okButton = findFirstButton(createBranchDialog, "Create");
if (okButton != null) {
okButton.setEnabled(true);
okButton.doClick();
}
break;
}
}
sleep(500);
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
assertEquals("Cannot_checkout_new_branch_when_having_conflicts", errMsg[0]);
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflict2Test method testCheckoutNewBranchWhenRepoInConflict_succeed_1.
/**
* <p><b>Description:</b> try to switch to a newly created branch from Git Branch Manager
* when repo is in conflict state.
* This should succeed.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCheckoutNewBranchWhenRepoInConflict_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 branch
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
// Pull to create conflict o text.txt
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(translator.getTranslation(Tags.CREATE_BRANCH) + "...")) {
SwingUtilities.invokeLater(() -> {
abstractAction.actionPerformed(null);
});
flushAWT();
JDialog createBranchDialog = findDialog(translator.getTranslation(Tags.CREATE_BRANCH));
JCheckBox checkoutBranchCheckBox = findCheckBox(createBranchDialog, Tags.CHECKOUT_BRANCH);
assertNotNull(checkoutBranchCheckBox);
checkoutBranchCheckBox.setSelected(true);
flushAWT();
JTextField branchNameTextField = findComponentNearJLabel(createBranchDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
branchNameTextField.setText("a_new_day");
JButton okButton = findFirstButton(createBranchDialog, "Create");
if (okButton != null) {
okButton.setEnabled(true);
okButton.doClick();
}
break;
}
}
sleep(500);
assertEquals("a_new_day", gitAccess.getRepository().getBranch());
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflictTest method testSwitchBranchFromGitBranchManager_checkoutConflict_1.
/**
* <p><b>Description:</b> try to switch branch from Git Branch Manager.
* 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_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("", "");
// 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 mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
sleep(1000);
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)) {
abstractAction.actionPerformed(null);
break;
}
}
sleep(1000);
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]);
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class BranchActionsTest method testDeleteLocalBranchAction.
/**
* Tests the action of deleting a local branch.
*
* @throws Exception
*/
public void testDeleteLocalBranchAction() throws Exception {
File file = new File(LOCAL_TEST_REPOSITORY + "local.txt");
file.createNewFile();
setFileContent(file, "local content");
// Make the first commit for the local repository and create a branch for it.
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
gitAccess.createBranch(LOCAL_BRANCH_NAME2);
gitAccess.fetch();
String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
// ------------- Delete first branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitTreeNode firstLeaf = (GitTreeNode) root.getFirstLeaf();
String firstLeafPath = (String) firstLeaf.getUserObject();
assertTrue(firstLeafPath.contains(Constants.R_HEADS));
String[] split = firstLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME1, split[split.length - 1]);
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction == null) {
// Probably separator. Continue.
continue;
}
if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.DELETE) + "...")) {
SwingUtilities.invokeLater(() -> {
abstractAction.actionPerformed(null);
});
JDialog deleteBranchDialog = findDialog(translator.getTranslation(Tags.DELETE_BRANCH));
JButton yesButton = findFirstButton(deleteBranchDialog, translator.getTranslation(Tags.YES));
yesButton.doClick();
break;
}
}
sleep(500);
gitAccess.fetch();
branchManagementPanel.refreshBranches();
flushAWT();
root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
StringBuilder actualTree = new StringBuilder();
BranchManagementTest.serializeTree(actualTree, root);
assertEquals("localRepository\n" + " refs/heads/\n" + " refs/heads/LocalBranch2\n" + " refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME + "\n", actualTree.toString());
}
use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.
the class BranchActionsTest method testCheckoutLocalBranchAction.
/**
* Tests the action of checkout of a local branch.
*
* @throws Exception
*/
public void testCheckoutLocalBranchAction() throws Exception {
File file = new File(LOCAL_TEST_REPOSITORY + "local.txt");
file.createNewFile();
setFileContent(file, "local content");
// Make the first commit for the local repository and create a branch for it.
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
gitAccess.createBranch(LOCAL_BRANCH_NAME2);
gitAccess.fetch();
String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
// ------------- Checkout the first branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitTreeNode firstLeaf = (GitTreeNode) root.getFirstLeaf();
String firstLeafPath = (String) firstLeaf.getUserObject();
assertTrue(firstLeafPath.contains(Constants.R_HEADS));
String[] branchPath = firstLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME1, branchPath[branchPath.length - 1]);
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CHECKOUT))) {
abstractAction.actionPerformed(null);
break;
}
}
sleep(500);
gitAccess.fetch();
assertEquals(LOCAL_BRANCH_NAME1, gitAccess.getRepository().getBranch());
// ------------- Checkout the next branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitTreeNode nextLeaf = (GitTreeNode) firstLeaf.getNextLeaf();
String nextLeafPath = (String) nextLeaf.getUserObject();
assertTrue(nextLeafPath.contains(Constants.R_HEADS));
branchPath = nextLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME2, branchPath[branchPath.length - 1]);
AbstractAction checkoutAction = branchTreeMenuActionsProvider.getCheckoutAction(nextLeaf);
if (checkoutAction != null) {
checkoutAction.actionPerformed(null);
}
sleep(500);
gitAccess.fetch();
assertEquals(LOCAL_BRANCH_NAME2, gitAccess.getRepository().getBranch());
}
Aggregations