Search in sources :

Example 1 with GitAccess

use of com.oxygenxml.git.service.GitAccess in project oxygen-git-client-addon by oxygenxml.

the class WorkingCopySelectorTest method testClearHistory.

/**
 * <p><b>Description:</b> test the "Clear history..." action.</p>
 * <p><b>Bug ID:</b> EXM-44205</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception When failing.
 */
public void testClearHistory() throws Exception {
    JFrame frame = new JFrame();
    try {
        GitControllerBase mock = Mockito.mock(GitControllerBase.class);
        GitAccess instance = GitAccess.getInstance();
        Mockito.when(mock.getGitAccess()).thenReturn(instance);
        WorkingCopySelectionPanel wcPanel = new WorkingCopySelectionPanel(mock, true);
        frame.getContentPane().add(wcPanel);
        frame.pack();
        // Showing the WC panel also initializes the combo
        SwingUtilities.invokeAndWait(() -> frame.setVisible(true));
        sleep(150);
        JComboBox<String> workingCopyCombo = wcPanel.getWorkingCopyCombo();
        ComboBoxModel<String> model = workingCopyCombo.getModel();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < model.getSize(); i++) {
            sb.append(model.getElementAt(i)).append("\n");
        }
        assertEquals("D:/folder/WC1\n" + "D:/folder/WC2\n" + "D:/folder_doi/WC\n" + "CLEAR_HISTORY\n", sb.toString());
        SwingUtilities.invokeAndWait(() -> workingCopyCombo.setSelectedItem("CLEAR_HISTORY"));
        sleep(150);
        sb = new StringBuilder();
        for (int i = 0; i < model.getSize(); i++) {
            sb.append(model.getElementAt(i)).append("\n");
        }
        assertEquals("D:/folder/WC1\n", sb.toString());
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitAccess(com.oxygenxml.git.service.GitAccess) WorkingCopySelectionPanel(com.oxygenxml.git.view.staging.WorkingCopySelectionPanel) JFrame(javax.swing.JFrame)

Example 2 with GitAccess

use of com.oxygenxml.git.service.GitAccess in project oxygen-git-client-addon by oxygenxml.

the class GitRevisionURLHandlerTest method testGetVersionContent.

/**
 * Tests the URLs that access the INDEX version of a file and the HEAD version.
 */
@Test
public void testGetVersionContent() throws Exception {
    /**
     * The local repository.
     */
    String localTestRepository = "target/test-resources/GitRevisionURLHandlerTest_testGetVersionContent/local";
    /**
     * The remote repository.
     */
    String remoteTestRepository = "target/test-resources/GitRevisionURLHandlerTest_testGetVersionContent/remote";
    GitAccess gitAccess = GitAccess.getInstance();
    Repository remoteRepo = createRepository(remoteTestRepository);
    // Create the local repository.
    Repository localRepo = createRepository(localTestRepository);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo, remoteRepo);
    // Create a new file.
    File file = new File(localTestRepository + "/test.txt");
    // Modify the newly created file.
    file.createNewFile();
    setFileContent(file, "initial content");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("First version.");
    // Change the file.
    setFileContent(file, "index content");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    // Change it again.
    setFileContent(file, "local content");
    // Get the INDEX version.
    String indexVersionURL = "git://" + VersionIdentifier.INDEX_OR_LAST_COMMIT + "/test.txt";
    assertEquals("index content", TestUtil.read(new URL(indexVersionURL)));
    // Get the HEAD version.
    String headVersionURL = "git://" + VersionIdentifier.LAST_COMMIT + "/test.txt";
    assertEquals("initial content", TestUtil.read(new URL(headVersionURL)));
}
Also used : Repository(org.eclipse.jgit.lib.Repository) GitAccess(com.oxygenxml.git.service.GitAccess) FileStatus(com.oxygenxml.git.service.entities.FileStatus) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 3 with GitAccess

use of com.oxygenxml.git.service.GitAccess in project oxygen-git-client-addon by oxygenxml.

the class StagingResourcesTreeModel method fileStatesChanged.

/**
 * File states changed.
 *
 * @param eventInfo Event information.
 */
public void fileStatesChanged(GitEventInfo eventInfo) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Tree model for index: " + inIndex + " event " + eventInfo);
    }
    GitAccess gitAccess = GitAccess.getInstance();
    switch(eventInfo.getGitOperation()) {
        case STAGE:
            if (inIndex) {
                insertNodes(gitAccess.getStagedFile(((FileGitEventInfo) eventInfo).getAffectedFilePaths()));
            } else {
                deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
            }
            break;
        case UNSTAGE:
            if (inIndex) {
                deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
            } else {
                // Things were taken out of the index / "staged" area.
                // The same resource might be present in the Unstaged and Staged. Remove old states.
                deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
                insertNodes(gitAccess.getUnstagedFiles(((FileGitEventInfo) eventInfo).getAffectedFilePaths()));
            }
            break;
        case COMMIT:
            if (inIndex) {
                clearModel();
            }
            break;
        case DISCARD:
            deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
            break;
        case MERGE_RESTART:
            clearModel();
            List<FileStatus> fileStatuses = inIndex ? gitAccess.getStagedFiles() : gitAccess.getUnstagedFiles();
            insertNodes(fileStatuses);
            break;
        case ABORT_REBASE:
        case CONTINUE_REBASE:
            clearModel();
            break;
        case ABORT_MERGE:
            deleteNodes(((FileGitEventInfo) eventInfo).getAffectedFileStatuses());
            break;
        default:
            // Nothing
            break;
    }
    fireTreeStructureChanged(this, null, null, null);
}
Also used : GitAccess(com.oxygenxml.git.service.GitAccess) FileStatus(com.oxygenxml.git.service.entities.FileStatus) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo)

Example 4 with GitAccess

use of com.oxygenxml.git.service.GitAccess in project oxygen-git-client-addon by oxygenxml.

the class GitTagsManager method getNoOfTags.

/**
 * The number of Git Tags
 *
 * @return an integer that represents the number of local Git Tags
 *
 * @throws GitAPIException
 */
public static int getNoOfTags() throws GitAPIException {
    GitAccess gitAccess = GitAccess.getInstance();
    List<Ref> refs = null;
    if (gitAccess.isRepoInitialized()) {
        refs = gitAccess.getGit().tagList().call();
    }
    return Optional.ofNullable(refs).map(List<Ref>::size).orElse(0);
}
Also used : Ref(org.eclipse.jgit.lib.Ref) GitAccess(com.oxygenxml.git.service.GitAccess)

Example 5 with GitAccess

use of com.oxygenxml.git.service.GitAccess in project oxygen-git-client-addon by oxygenxml.

the class DiffPresenterTest method testExistingFileDiff.

/**
 * Scenario 2:
 * - an existing file modified. Added into the index.
 * - the new file modified again.
 * To test:
 * - Diff in not-staged: compares the modified version with the index version
 * - Diff in staged: compares the index version with the remote one.
 *
 * @throws Exception If it fails.
 */
@Test
public void testExistingFileDiff() throws Exception {
    /**
     * The local repository.
     */
    String localTestRepository = "target/test-resources/local";
    /**
     * The remote repository.
     */
    String remoteTestRepository = "target/test-resources/remote";
    GitAccess gitAccess = GitAccess.getInstance();
    Repository remoteRepo = createRepository(remoteTestRepository);
    // Create the local repository.
    Repository localRepo = createRepository(localTestRepository);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo, remoteRepo);
    // Create a new file.
    File file = new File(localTestRepository + "/test.txt");
    file.createNewFile();
    // Modify the newly created file.
    setFileContent(file, "initial content");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("First version.");
    // Change the file.
    setFileContent(file, "index content");
    // Add it to the index.
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    // Change it again.
    setFileContent(file, "local content");
    FileStatus fileStatus = new FileStatus(GitChangeType.MODIFIED, "test.txt");
    GitControllerBase gitCtrl = Mockito.mock(GitControllerBase.class);
    // Mock the translator.
    Translator translator = Mockito.mock(Translator.class);
    Mockito.when(translator.getTranslation(Mockito.anyString())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return (String) invocation.getArguments()[0];
        }
    });
    // Diff the first WC local file.
    DiffPresenter.showDiff(fileStatus, gitCtrl);
    assertNotNull(leftDiff);
    assertNotNull(rightDiff);
    String localVersionURL = file.toURI().toURL().toString();
    assertEquals("The local file should be on the left side, but was: " + localVersionURL, localVersionURL, leftDiff.toString());
    String indexVersionURL = "git://" + VersionIdentifier.INDEX_OR_LAST_COMMIT + "/test.txt";
    assertEquals("The index version should be on the right, but was: " + rightDiff.toString(), indexVersionURL, rightDiff.toString());
    leftDiff = null;
    rightDiff = null;
    // Diff the index file.
    fileStatus = new FileStatus(GitChangeType.CHANGED, "test.txt");
    DiffPresenter.showDiff(fileStatus, gitCtrl);
    assertNotNull(leftDiff);
    assertNotNull(rightDiff);
    assertEquals("The index version should be on the left, but was: " + leftDiff.toString(), indexVersionURL, leftDiff.toString());
    String headVersionURL = "git://" + VersionIdentifier.LAST_COMMIT + "/test.txt";
    assertEquals("The head version should be on the right, but was: " + rightDiff.toString(), headVersionURL, rightDiff.toString());
    // Assert content.
    assertEquals("index content", TestUtil.read(new URL(indexVersionURL)));
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) Repository(org.eclipse.jgit.lib.Repository) GitAccess(com.oxygenxml.git.service.GitAccess) FileStatus(com.oxygenxml.git.service.entities.FileStatus) Translator(com.oxygenxml.git.translator.Translator) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

GitAccess (com.oxygenxml.git.service.GitAccess)11 File (java.io.File)8 FileStatus (com.oxygenxml.git.service.entities.FileStatus)7 Test (org.junit.Test)6 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)5 URL (java.net.URL)5 Repository (org.eclipse.jgit.lib.Repository)5 List (java.util.List)4 GitOperationScheduler (com.oxygenxml.git.service.GitOperationScheduler)2 GitTestBase (com.oxygenxml.git.service.GitTestBase)2 RevCommitUtil (com.oxygenxml.git.service.RevCommitUtil)2 GitChangeType (com.oxygenxml.git.service.entities.GitChangeType)2 RepoGenerationScript (com.oxygenxml.git.utils.script.RepoGenerationScript)2 GitController (com.oxygenxml.git.view.event.GitController)2 BufferedReader (java.io.BufferedReader)2 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 PrintWriter (java.io.PrintWriter)2 Iterator (java.util.Iterator)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2