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]);
}
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());
}
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());
}
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());
}
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);
}
Aggregations