Search in sources :

Example 6 with WorkingCopyGitEventInfo

use of com.oxygenxml.git.view.event.WorkingCopyGitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method repositoryOpened.

/**
 * Actions to do after a repository was opened.
 *
 * @param workingCopy The WC.
 */
private void repositoryOpened(File workingCopy) {
    // Start intercepting authentication requests.
    AuthenticationInterceptor.bind(getHostName());
    if (LOGGER.isDebugEnabled()) {
        logSshKeyLoadingData();
    }
    fireOperationSuccessfullyEnded(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, workingCopy));
}
Also used : WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)

Example 7 with WorkingCopyGitEventInfo

use of com.oxygenxml.git.view.event.WorkingCopyGitEventInfo in project oxygen-git-client-addon by oxygenxml.

the class GitEditorVariables2Test method testCache.

/**
 * <p><b>Description:</b> test Git editor variables cache.</p>
 * <p><b>Bug ID:</b> EXM-46457</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testCache() throws Exception {
    Map<String, String> cache = editorVariablesResolver.getEditorVarsCacheFromTests();
    assertTrue(cache.isEmpty());
    String resolved = editorVariablesResolver.resolveEditorVariables("bla", null);
    assertEquals("bla", resolved);
    assertTrue(cache.isEmpty());
    // Short branch - git access should be called
    resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR, null);
    assertEquals("main", resolved);
    assertEquals("{${git(short_branch_name)}=main}", cache.toString());
    assertEquals(1, noOfShortBranchCalls);
    // Short branch again - get it from cache
    resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR, null);
    assertEquals("main", resolved);
    assertEquals("{${git(short_branch_name)}=main}", cache.toString());
    assertEquals(1, noOfShortBranchCalls);
    // Full branch name - git access should be called
    resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
    assertEquals("refs/heads/main", resolved);
    assertEquals(2, cache.size());
    assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
    assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
    assertEquals(1, noOfFullBranchCalls);
    // Full branch name again - get it from the cache
    resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
    assertEquals("refs/heads/main", resolved);
    assertEquals(2, cache.size());
    assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
    assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
    assertEquals(1, noOfFullBranchCalls);
    // WC name + WC path + WC URL - get them from git access, but request the WC only once
    resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.WORKING_COPY_NAME_EDITOR_VAR + " " + GitEditorVariablesNames.WORKING_COPY_PATH_EDITOR_VAR + " " + GitEditorVariablesNames.WORKING_COPY_URL_EDITOR_VAR, null);
    String expected = "EditorVariablesTest " + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath() + " " + new File(LOCAL_TEST_REPOSITORY).toURI().toURL();
    assertEquals(expected, resolved);
    assertEquals(5, cache.size());
    assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
    assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
    assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
    assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
    assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
    assertEquals(1, noOfWCCalls);
    // WC name + WC path + WC URL again- get them from git access
    resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.WORKING_COPY_NAME_EDITOR_VAR, null);
    assertEquals("EditorVariablesTest", resolved);
    assertEquals(5, cache.size());
    assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
    assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
    assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
    assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
    assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
    assertEquals(1, noOfWCCalls);
    // Simulate branch switch
    editorVariablesResolver.getGitEventListenerFromTests().operationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.CHECKOUT, ""));
    assertEquals(3, cache.size());
    assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
    assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
    assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
    // Short + full branch name again - take them from git access
    resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR + " " + GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
    assertEquals("main refs/heads/main", resolved);
    assertEquals(5, cache.size());
    assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
    assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
    assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
    assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
    assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
    assertEquals(2, noOfShortBranchCalls);
    assertEquals(2, noOfFullBranchCalls);
    // Simulate repo switch
    editorVariablesResolver.getGitEventListenerFromTests().operationSuccessfullyEnded(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, new File(".")));
    assertTrue(cache.isEmpty());
}
Also used : WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) File(java.io.File)

Aggregations

WorkingCopyGitEventInfo (com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)7 File (java.io.File)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 IOException (java.io.IOException)2 SSHCapableUserCredentialsProvider (com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider)1 GitEventAdapter (com.oxygenxml.git.service.GitEventAdapter)1 NoRepositorySelected (com.oxygenxml.git.service.NoRepositorySelected)1 BranchGitEventInfo (com.oxygenxml.git.view.event.BranchGitEventInfo)1 GitEventInfo (com.oxygenxml.git.view.event.GitEventInfo)1 GitOperation (com.oxygenxml.git.view.event.GitOperation)1 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)1 StashApplyFailureWithStatusException (com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException)1 URISyntaxException (java.net.URISyntaxException)1 SshException (org.apache.sshd.common.SshException)1 CloneCommand (org.eclipse.jgit.api.CloneCommand)1 AbortedByHookException (org.eclipse.jgit.api.errors.AbortedByHookException)1 CheckoutConflictException (org.eclipse.jgit.api.errors.CheckoutConflictException)1 ConcurrentRefUpdateException (org.eclipse.jgit.api.errors.ConcurrentRefUpdateException)1 NoHeadException (org.eclipse.jgit.api.errors.NoHeadException)1 NoMessageException (org.eclipse.jgit.api.errors.NoMessageException)1