use of com.oxygenxml.git.view.branches.BranchManagementPanel in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflict2Test method testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_2.
/**
* <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, but not on the resource that is in pull conflict.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_2() 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());
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.branches.BranchManagementPanel in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflict2Test method testCheckoutNewBranch_checkoutConflict_1.
/**
* <p><b>Description:</b> try to switch to a newly created branch from Git Branch Manager.
* Repo is not in conflict.
* The branch checkout generates a checkout conflict.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCheckoutNewBranch_checkoutConflict_1() throws Exception {
// Push from main branch
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("", "");
// Create new_branch, change file and commit
gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "altfel");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("commit on ew branch");
// Move to main branch and change file
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();
sleep(500);
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(gitCtrl);
// 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);
SwingUtilities.invokeLater(() -> okButton.doClick());
flushAWT();
}
break;
}
}
sleep(1000);
Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
JButton yesButton = TestUtil.findButton(focusedWindow, translator.getTranslation(Tags.MOVE_CHANGES));
yesButton.doClick();
flushAWT();
sleep(1000);
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
assertEquals("Cannot_checkout_new_branch_because_uncommitted_changes", errMsg[0]);
}
use of com.oxygenxml.git.view.branches.BranchManagementPanel 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]);
}
use of com.oxygenxml.git.view.branches.BranchManagementPanel 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]);
}
use of com.oxygenxml.git.view.branches.BranchManagementPanel in project oxygen-git-client-addon by oxygenxml.
the class GitAccessRevertMergingConflictsTest method testRevertCommitWithRepoInConflict.
/**
* <p><b>Description:</b> test the "Revert commit" action when the repo has conflicts.</p>
* <p><b>Bug ID:</b> EXM-47154</p>
*
* @author Tudosie Razvan
*
* @throws Exception
*/
@Test
public void testRevertCommitWithRepoInConflict() throws Exception {
File file1 = new File(LOCAL_TEST_REPOSITORY, "local1.txt");
File file2 = new File(LOCAL_TEST_REPOSITORY, "local2.txt");
file1.createNewFile();
file2.createNewFile();
setFileContent(file1, "local file 1 content");
setFileContent(file2, "local file 2 content");
// Make the first commit for the local repository and create a new branch
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
gitAccess.commit("First local commit on main.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
// ------------- Checkout branch: LOCAL_BRANCH_NAME1 -------------
gitAccess.setBranch(LOCAL_BRANCH_NAME1);
// Commit on this branch
setFileContent(file1, "local file 1 on new branch");
setFileContent(file2, "local file 2 on new branch");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
gitAccess.commit("Commit on secondary branch");
// ------------- Move to the main branch and commit something there
// ---------------
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
setFileContent(file1, "local file 1 modifications");
setFileContent(file2, "local file 2 modifications");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
gitAccess.commit("2nd commit on main branch");
// Merge secondary branch into main
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
GitTreeNode secondaryBranchNode = (GitTreeNode) root.getFirstLeaf();
String secondaryBranchPath = (String) secondaryBranchNode.getUserObject();
assertTrue(secondaryBranchPath.contains(Constants.R_HEADS));
List<AbstractAction> actionsForSecondaryBranch = branchTreeMenuActionsProvider.getActionsForNode(secondaryBranchNode);
for (AbstractAction action : actionsForSecondaryBranch) {
if (action != null) {
String actionName = action.getValue(AbstractAction.NAME).toString();
if ("Merge_Branch1_Into_Branch2".equals(actionName)) {
SwingUtilities.invokeLater(() -> action.actionPerformed(null));
break;
}
}
}
flushAWT();
// Confirm merge dialog
JDialog mergeOkDialog = findDialog(translator.getTranslation(Tags.MERGE_BRANCHES));
JButton mergeOkButton = findFirstButton(mergeOkDialog, translator.getTranslation(Tags.YES));
mergeOkButton.doClick();
flushAWT();
sleep(300);
JDialog conflictMergeDialog = findDialog(translator.getTranslation(Tags.MERGE_CONFLICTS_TITLE));
assertNotNull(conflictMergeDialog);
conflictMergeDialog.setVisible(false);
conflictMergeDialog.dispose();
flushAWT();
sleep(200);
assertTrue(TestUtil.read(file1.toURI().toURL()).contains("<<<<<<< HEAD\n" + "local file 1 modifications\n" + "=======\n" + "local file 1 on new branch\n" + ">>>>>>>"));
assertTrue(TestUtil.read(file2.toURI().toURL()).contains("<<<<<<< HEAD\n" + "local file 2 modifications\n" + "=======\n" + "local file 2 on new branch\n" + ">>>>>>>"));
List<CommitCharacteristics> commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
String initialHistory = "[ Uncommitted_changes , DATE , * , * , null , null ]\n" + "[ 2nd commit on main branch , DATE , AlexJitianu <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ First local commit on main. , DATE , AlexJitianu <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Added a new file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ Modified a file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 4 , AlexJitianu , [5] ]\n" + "[ First commit. , DATE , AlexJitianu <alex_jitianu@sync.ro> , 5 , AlexJitianu , null ]\n" + "";
String regex = "(([0-9])|([0-2][0-9])|([3][0-1]))\\ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\ \\d{4}";
assertEquals(initialHistory, dumpHistory(commitsCharacteristics).replaceAll(regex, "DATE"));
CommitCharacteristics commitToRevert = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker()).get(4);
RevertCommitAction revertAction = new RevertCommitAction(commitToRevert);
SwingUtilities.invokeLater(() -> revertAction.actionPerformed(null));
flushAWT();
JDialog revertConfirmationDlg = findDialog(Tags.REVERT_COMMIT);
JTextArea confirmationTextArea = findFirstTextArea(revertConfirmationDlg);
assertEquals(Tags.REVERT_COMMIT_CONFIRMATION, confirmationTextArea.getText().toString());
JButton revertOkButton = findFirstButton(revertConfirmationDlg, Tags.YES);
revertOkButton.doClick();
flushAWT();
sleep(300);
assertEquals("", errMsg[0]);
}
Aggregations