Search in sources :

Example 96 with FileStatus

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("", "");
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) ObjectId(org.eclipse.jgit.lib.ObjectId) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 97 with FileStatus

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());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) File(java.io.File) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 98 with FileStatus

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());
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) File(java.io.File) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 99 with FileStatus

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());
}
Also used : Action(javax.swing.Action) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JTable(javax.swing.JTable) File(java.io.File) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) URL(java.net.URL) Test(org.junit.Test)

Example 100 with FileStatus

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;
}
Also used : CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) Arrays(java.util.Arrays) HistoryViewContextualMenuPresenter(com.oxygenxml.git.view.history.HistoryViewContextualMenuPresenter) Date(java.util.Date) HistoryPanel(com.oxygenxml.git.view.history.HistoryPanel) GitController(com.oxygenxml.git.view.event.GitController) Action(javax.swing.Action) TableModelListener(javax.swing.event.TableModelListener) GitTestBase(com.oxygenxml.git.service.GitTestBase) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitAccess(com.oxygenxml.git.service.GitAccess) JMenuItem(javax.swing.JMenuItem) PowerMockito(org.powermock.api.mockito.PowerMockito) TableModelEvent(javax.swing.event.TableModelEvent) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Semaphore(java.util.concurrent.Semaphore) JPopupMenu(javax.swing.JPopupMenu) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) MenuElement(javax.swing.MenuElement) HistoryCommitTableModel(com.oxygenxml.git.view.history.HistoryCommitTableModel) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Ignore(org.junit.Ignore) JTable(javax.swing.JTable) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) HistoryTableAffectedFilesModel(com.oxygenxml.git.view.history.HistoryTableAffectedFilesModel) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) Action(javax.swing.Action) JMenuItem(javax.swing.JMenuItem) HistoryViewContextualMenuPresenter(com.oxygenxml.git.view.history.HistoryViewContextualMenuPresenter) MenuElement(javax.swing.MenuElement) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

FileStatus (com.oxygenxml.git.service.entities.FileStatus)210 File (java.io.File)136 Test (org.junit.Test)77 ArrayList (java.util.ArrayList)58 GitController (com.oxygenxml.git.view.event.GitController)53 List (java.util.List)50 Repository (org.eclipse.jgit.lib.Repository)49 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)38 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)33 JButton (javax.swing.JButton)33 SelectedResourcesProvider (com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider)26 IOException (java.io.IOException)25 AbstractAction (javax.swing.AbstractAction)24 JDialog (javax.swing.JDialog)24 GitResourceContextualMenu (com.oxygenxml.git.view.staging.GitResourceContextualMenu)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 URL (java.net.URL)18 Action (javax.swing.Action)18 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)16