Search in sources :

Example 1 with WorkingCopyGitEventInfo

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

the class GitAccess method clone.

/**
 * Creates a local clone of the given repository and loads it.
 *
 * @param url Remote repository to clone.
 * @param directory Local directory in which to create the clone.
 * @param progressDialog Progress support.
 * @param branchName     The name of the branch to clone and checkout. Must be
 *                       specified as full ref names (e.g.
 *                       "refs/heads/hotfixes/17.0").
 *
 * @throws GitAPIException
 */
public void clone(URIish url, File directory, final ProgressDialog progressDialog, String branchName) throws GitAPIException {
    closeRepo();
    // Intercept all authentication requests.
    String host = url.getHost();
    AuthenticationInterceptor.bind(host);
    ProgressMonitor progressMonitor = createCloneProgressMonitor(progressDialog);
    if (progressDialog != null) {
        progressDialog.setNote("Initializing...");
    }
    CloneCommand cloneCommand = Git.cloneRepository().setCloneSubmodules(true).setURI(url.toString()).setDirectory(directory).setCredentialsProvider(AuthUtil.getCredentialsProvider(host)).setProgressMonitor(progressMonitor);
    fireOperationAboutToStart(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, directory));
    try {
        if (branchName != null) {
            git = cloneCommand.setBranch(branchName).call();
        } else {
            git = cloneCommand.call();
        }
        fireOperationSuccessfullyEnded(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, directory));
    } catch (GitAPIException ex) {
        fireOperationFailed(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, directory), ex);
        throw ex;
    }
}
Also used : ProgressMonitor(org.eclipse.jgit.lib.ProgressMonitor) CloneCommand(org.eclipse.jgit.api.CloneCommand) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)

Example 2 with WorkingCopyGitEventInfo

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

the class GitAccess method createNewRepository.

/**
 * Creates a blank new Repository.
 *
 * @param path A string that specifies the git Repository folder
 *
 * @throws GitAPIException
 */
public void createNewRepository(String path) throws GitAPIException {
    File wc = new File(path);
    fireOperationAboutToStart(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, wc));
    closeRepo();
    try {
        git = Git.init().setInitialBranch(DEFAULT_BRANCH_NAME).setBare(false).setDirectory(wc).call();
        fireOperationSuccessfullyEnded(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, wc));
    } catch (GitAPIException e) {
        fireOperationFailed(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, wc), e);
        throw e;
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) File(java.io.File)

Example 3 with WorkingCopyGitEventInfo

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

the class OxygenGitPluginExtension method customizeGitStagingView.

/**
 * Customize the Git Staging view.
 *
 * @param viewInfo View information.
 */
private void customizeGitStagingView(final ViewInfo viewInfo, final GitActionsManager gitActionsManager) {
    boolean shouldRecreateStagingPanel = stagingPanel == null;
    if (shouldRecreateStagingPanel) {
        stagingPanel = new StagingPanel(gitRefreshSupport, gitController, OxygenGitPluginExtension.this, gitActionsManager);
        gitRefreshSupport.setStagingPanel(stagingPanel);
    }
    viewInfo.setComponent(stagingPanel);
    GitOperationUtil.installMouseBusyCursor(gitController, stagingPanel);
    gitController.addGitListener(new GitEventAdapter() {

        @Override
        public void operationAboutToStart(GitEventInfo info) {
        // not needed
        }

        @Override
        public void operationSuccessfullyEnded(GitEventInfo info) {
            final GitOperation operation = info.getGitOperation();
            if (operation == GitOperation.CHECKOUT || operation == GitOperation.CONTINUE_REBASE || operation == GitOperation.RESET_TO_COMMIT || operation == GitOperation.OPEN_WORKING_COPY || operation == GitOperation.MERGE || operation == GitOperation.COMMIT || operation == GitOperation.REVERT_COMMIT || operation == GitOperation.STASH_CREATE || operation == GitOperation.STASH_DROP || operation == GitOperation.STASH_APPLY || operation == GitOperation.UPDATE_CONFIG_FILE || operation == GitOperation.STASH_POP || operation == GitOperation.CHECKOUT_FILE || operation == GitOperation.CHECKOUT_COMMIT || operation == GitOperation.CREATE_TAG || operation == GitOperation.DELETE_TAG || operation == GitOperation.DISCARD) {
                gitRefreshSupport.call();
                if (operation == GitOperation.CHECKOUT || operation == GitOperation.MERGE) {
                    try {
                        FileUtil.refreshProjectView();
                    } catch (NoRepositorySelected e) {
                        LOGGER.debug(e.getMessage(), e);
                    }
                } else if (operation == GitOperation.OPEN_WORKING_COPY && GitAccess.getInstance().getBranchInfo().isDetached()) {
                    treatDetachedHead((WorkingCopyGitEventInfo) info);
                }
            }
        }

        @Override
        public void operationFailed(GitEventInfo info, Throwable t) {
            final GitOperation operation = info.getGitOperation();
            if (operation == GitOperation.CONTINUE_REBASE || operation == GitOperation.RESET_TO_COMMIT) {
                gitRefreshSupport.call();
            }
        }
    });
    gitRefreshSupport.call();
    viewInfo.setIcon(Icons.getIcon(Icons.GIT_ICON));
    viewInfo.setTitle(translator.getTranslation(Tags.GIT_STAGING));
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) GitOperation(com.oxygenxml.git.view.event.GitOperation) GitEventAdapter(com.oxygenxml.git.service.GitEventAdapter) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel)

Example 4 with WorkingCopyGitEventInfo

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

the class GitAccess method setSubmodule.

/**
 * Sets the given submodule as the current repository
 *
 * @param submodule - the name of the submodule.
 *
 * @throws IOException Failed to load the submodule.
 * @throws GitAPIException Failed to load the submodule.
 */
public void setSubmodule(String submodule) throws IOException, GitAPIException {
    Repository parentRepository = git.getRepository();
    File submoduleDir = SubmoduleWalk.getSubmoduleDirectory(parentRepository, submodule);
    fireOperationAboutToStart(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, submoduleDir, true));
    try {
        Repository submoduleRepository = SubmoduleWalk.getSubmoduleRepository(parentRepository, submodule);
        if (submoduleRepository == null) {
            // The submodule wasn't updated.
            git.submoduleInit().call();
            CredentialsProvider credentialsProvider = AuthUtil.getCredentialsProvider(getHostName());
            git.submoduleUpdate().setCredentialsProvider(credentialsProvider).call();
            submoduleRepository = SubmoduleWalk.getSubmoduleRepository(parentRepository, submodule);
        }
        // Close the current repository.
        closeRepo();
        git = Git.wrap(submoduleRepository);
        // Start intercepting authentication requests.
        AuthenticationInterceptor.bind(getHostName());
        fireOperationSuccessfullyEnded(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, submoduleDir, true));
    } catch (Exception e) {
        fireOperationFailed(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, submoduleDir, true), e);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) SSHCapableUserCredentialsProvider(com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) File(java.io.File) SshException(org.apache.sshd.common.SshException) NoHeadException(org.eclipse.jgit.api.errors.NoHeadException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) IOException(java.io.IOException) UnmergedPathsException(org.eclipse.jgit.api.errors.UnmergedPathsException) RevisionSyntaxException(org.eclipse.jgit.errors.RevisionSyntaxException) URISyntaxException(java.net.URISyntaxException) CheckoutConflictException(org.eclipse.jgit.api.errors.CheckoutConflictException) NoMessageException(org.eclipse.jgit.api.errors.NoMessageException) AbortedByHookException(org.eclipse.jgit.api.errors.AbortedByHookException) StashApplyFailureException(org.eclipse.jgit.api.errors.StashApplyFailureException) StashApplyFailureWithStatusException(com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException) NoMergeBaseException(org.eclipse.jgit.errors.NoMergeBaseException) ConcurrentRefUpdateException(org.eclipse.jgit.api.errors.ConcurrentRefUpdateException) WrongRepositoryStateException(org.eclipse.jgit.api.errors.WrongRepositoryStateException) TransportException(org.eclipse.jgit.api.errors.TransportException)

Example 5 with WorkingCopyGitEventInfo

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

the class GitAccess method openRepository.

/**
 * Open repo.
 *
 * @param path The path of the repo to open.
 *
 * @throws IOException
 */
private void openRepository(String path) throws IOException {
    final File repo = new File(path + "/.git");
    if (!isCurrentRepo(repo)) {
        File workingCopy = repo.getParentFile();
        fireOperationAboutToStart(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, workingCopy));
        closeRepo();
        try {
            git = Git.open(repo);
            repositoryOpened(workingCopy);
        } catch (IOException e) {
            fireOperationFailed(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, workingCopy), e);
            throw e;
        }
    }
}
Also used : WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) IOException(java.io.IOException) 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