use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class GitAccessCommitFileContentTest method testBaseCommitFile.
@Test
public void testBaseCommitFile() throws Exception {
pushOneFileToRemote("test 1");
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
OptionsManager.getInstance().saveSelectedRepository(SECOND_LOCAL_TEST_REPOSITORY);
pull("", "", PullType.MERGE_FF, false);
gitAccess.closeRepo();
gitAccess = GitAccess.getInstance();
pushOneFileToRemote("test 2");
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
OptionsManager.getInstance().saveSelectedRepository(SECOND_LOCAL_TEST_REPOSITORY);
PrintWriter out = new PrintWriter(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
out.println("teeeeeest");
out.close();
gitAccess.add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
gitAccess.commit("conflict");
pull("", "", PullType.MERGE_FF, false);
ObjectId commit = gitAccess.getCommit(Commit.MINE, "test.txt");
ObjectLoader open = gitAccess.getRepository().open(commit);
String actual = new String(open.getBytes());
String expected = "teeeeeest\n";
assertEquals(expected, actual);
commit = gitAccess.getCommit(Commit.THEIRS, "test.txt");
open = gitAccess.getRepository().open(commit);
actual = new String(open.getBytes());
expected = "test 2\n";
assertEquals(expected, actual);
commit = gitAccess.getCommit(Commit.BASE, "test.txt");
open = gitAccess.getRepository().open(commit);
actual = new String(open.getBytes());
expected = "test 1\n";
assertEquals(expected, actual);
gitAccess.addAll(gitAccess.getUnstagedFiles());
gitAccess.commit("pocpoc");
push("", "");
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class GitAccessCommitTest method testSingleFileCommit.
@Test
public void testSingleFileCommit() throws Exception {
File file = new File(LOCAL_TEST_REPOSITPRY + "/test.txt");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
gitAccess.add(new FileStatus(GitChangeType.ADD, file.getName()));
gitAccess.commit("single file added");
Repository repository = gitAccess.getRepository();
RevWalk walk = null;
TreeWalk treeWalk = null;
List<String> actualFileNamesPath = new ArrayList<>();
String actualMessage = null;
try {
Ref head = repository.exactRef(Constants.HEAD);
walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(head.getObjectId());
actualMessage = commit.getFullMessage();
treeWalk = new TreeWalk(repository);
treeWalk.reset(commit.getTree());
while (treeWalk.next()) {
String path = treeWalk.getPathString();
actualFileNamesPath.add(path);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
walk.close();
treeWalk.close();
}
String expectedMessage = "single file added";
List<String> expectedFileNamesPath = new ArrayList<>();
expectedFileNamesPath.add("test.txt");
assertEquals(expectedMessage, actualMessage);
assertEquals(expectedFileNamesPath.toString(), actualFileNamesPath.toString());
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class GitAccessCommitTest method testMultipleFileCommit.
@Test
public void testMultipleFileCommit() throws Exception {
int n = 3;
List<FileStatus> files = new ArrayList<>();
for (int i = 0; i < n; i++) {
File file = new File(LOCAL_TEST_REPOSITPRY + "/test" + i + ".txt");
files.add(new FileStatus(GitChangeType.ADD, file.getName()));
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
gitAccess.addAll(files);
gitAccess.commit("multiple files added");
Repository repository = gitAccess.getRepository();
RevWalk walk = null;
TreeWalk treeWalk = null;
List<String> actualFileNamesPath = new ArrayList<>();
String actualMessage = null;
try {
Ref head = repository.exactRef(Constants.HEAD);
walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(head.getObjectId());
actualMessage = commit.getFullMessage();
treeWalk = new TreeWalk(repository);
treeWalk.reset(commit.getTree());
while (treeWalk.next()) {
String path = treeWalk.getPathString();
actualFileNamesPath.add(path);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
walk.close();
treeWalk.close();
}
String expectedMessage = "multiple files added";
List<String> expectedFileNamesPath = new ArrayList<>();
expectedFileNamesPath.add("test0.txt");
expectedFileNamesPath.add("test1.txt");
expectedFileNamesPath.add("test2.txt");
assertEquals(expectedMessage, actualMessage);
assertEquals(expectedFileNamesPath.toString(), actualFileNamesPath.toString());
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class HistoryPanel2Test method testMultipleSelectionHistoryActions.
/**
* Tests the actions presented for multiple selection in the history panel.
*
* EXM-44448
*
* @throws Exception If it fails.
*/
@Test
public void testMultipleSelectionHistoryActions() throws Exception {
generateRepositoryAndLoad(getClass().getClassLoader().getResource("scripts/file_content_script.txt"), new File("target/gen/HistoryPanelTest/testMultipleSelectionHistoryActions"));
List<CommitCharacteristics> commitsCharacteristics = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
String dump = dumpHistory(commitsCharacteristics, true);
String expected = "[ Third. , {date} , Alex <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Second. , {date} , Alex <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , {date} , Alex <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
assertEquals(expected, dump);
historyPanel.showRepositoryHistory();
waitForScheduler();
flushAWT();
sleep(300);
JTable historyTable = historyPanel.getHistoryTable();
HistoryCommitTableModel model = (HistoryCommitTableModel) historyTable.getModel();
dump = dumpHistory(model.getAllCommits(), true);
assertEquals(expected, dump);
// ---------------
// Invoke the Diff action to see if the built URLs are O.K.
// ---------------
CommitCharacteristics cc1 = model.getAllCommits().get(0);
CommitCharacteristics cc3 = model.getAllCommits().get(2);
FileStatus fileStatus = new FileStatus(GitChangeType.CHANGED, "file1.txt");
Action action = getCompareWithEachOther(fileStatus, cc1, cc3);
action.actionPerformed(null);
assertEquals("Unexpected number of URLs intercepted in the comparison support:" + urls2compare.toString(), 2, urls2compare.size());
URL left = urls2compare.get(0);
URL right = urls2compare.get(1);
assertEquals("git://" + cc1.getCommitId() + "/file1.txt", left.toString());
assertEquals("git://" + cc3.getCommitId() + "/file1.txt", right.toString());
// ///////////////
// Test the open multiple files
// ////////////////
CommitCharacteristics cc2 = model.getAllCommits().get(1);
Action open = getOpenFileAction(fileStatus, cc1, cc2, cc3);
open.actionPerformed(null);
assertEquals("[" + "git://" + cc1.getCommitId() + "/file1.txt" + ", " + "git://" + cc2.getCommitId() + "/file1.txt" + ", " + "git://" + cc3.getCommitId() + "/file1.txt" + "]", toOpen.toString());
}
use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.
the class HistoryPanelTestBase method getAllActions.
/**
* Gets all the actions from the contextual menu for the given file.
*
* @param fileStatus File.
* @param cc Revision information.
*
* @return All the actions that will be put in the contextual menu for the received resource.
*
* @throws IOException
* @throws GitAPIException
*/
protected List<Action> getAllActions(FileStatus fileStatus, CommitCharacteristics cc) throws IOException, GitAPIException {
HistoryViewContextualMenuPresenter menuPresenter = new HistoryViewContextualMenuPresenter(PowerMockito.mock(GitControllerBase.class));
JPopupMenu jPopupMenu = new JPopupMenu();
menuPresenter.populateContextualActionsHistoryContext(jPopupMenu, fileStatus.getFileLocation(), cc);
MenuElement[] subElements = jPopupMenu.getSubElements();
List<Action> actions = Arrays.asList(subElements).stream().map(t -> ((JMenuItem) t).getAction()).collect(Collectors.toList());
return actions;
}
Aggregations