Search in sources :

Example 1 with GitEventInfo

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

the class GitAccess method deleteTag.

/**
 * Delete a given Tag
 *
 * @param name The name of the tag to be deleted
 *
 * @throws GitAPIException
 */
public void deleteTag(String name) throws GitAPIException {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.DELETE_TAG));
    try {
        getGit().tagDelete().setTags(name).call();
        fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.DELETE_TAG));
    } catch (GitAPIException e) {
        LOGGER.error(e.getMessage(), e);
        fireOperationFailed(new GitEventInfo(GitOperation.DELETE_TAG), e);
        throw e;
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)

Example 2 with GitEventInfo

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

the class GitAccess method resetToCommit.

/**
 * Resets the current branch to a specified commit.
 *
 * @param resetType The reset type to perform on the current branch.
 * @param commitId  The commit id to which to reset.
 */
public void resetToCommit(ResetType resetType, String commitId) {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.RESET_TO_COMMIT));
    try {
        git.reset().setMode(resetType).setRef(commitId).call();
        fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.RESET_TO_COMMIT));
    } catch (GitAPIException e) {
        fireOperationFailed(new GitEventInfo(GitOperation.RESET_TO_COMMIT), e);
        PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(e.getMessage(), e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)

Example 3 with GitEventInfo

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

the class GitAccess method doCheckoutCommit.

/**
 * Used to do a checkout commit. If the branchName is null, no branch will de created.
 *
 * @param checkoutCommand         Checkout command to do the checkout.
 * @param branchName              The new branch name.
 *
 * @throws GitAPIException Errors while invoking git commands.
 */
private void doCheckoutCommit(CheckoutCommand checkoutCommand, String branchName) throws GitAPIException {
    if (checkoutCommand != null) {
        fireOperationAboutToStart(new GitEventInfo(GitOperation.CHECKOUT_COMMIT));
        checkoutCommand.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);
        if (branchName != null) {
            checkoutCommand.setCreateBranch(true).setName(branchName);
        } else {
            checkoutCommand.setCreateBranch(false).setName(Constants.HEAD);
        }
        try {
            checkoutCommand.call();
        } catch (GitAPIException e) {
            fireOperationFailed(new GitEventInfo(GitOperation.CHECKOUT_COMMIT), e);
            throw e;
        }
        fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.CHECKOUT_COMMIT));
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)

Example 4 with GitEventInfo

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

the class GitAccess method restartMerge.

/**
 * Restore to the initial state of the repository. Only applicable if the
 * repository has conflicts
 *
 * @return The restart merge task.
 */
@SuppressWarnings("java:S1452")
public ScheduledFuture<?> restartMerge() {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.MERGE_RESTART));
    return GitOperationScheduler.getInstance().schedule(() -> {
        try {
            Repository repo = getRepository();
            RepositoryState repositoryState = repo.getRepositoryState();
            if (repositoryState == RepositoryState.REBASING_MERGE) {
                git.rebase().setOperation(Operation.ABORT).call();
                // EXM-47461 Should update submodules as well.
                CredentialsProvider credentialsProvider = AuthUtil.getCredentialsProvider(getHostName());
                pull(credentialsProvider, PullType.REBASE, OptionsManager.getInstance().getUpdateSubmodulesOnPull());
            } else {
                AnyObjectId commitToMerge = repo.resolve("MERGE_HEAD");
                git.clean().call();
                git.reset().setMode(ResetType.HARD).call();
                git.merge().include(commitToMerge).setStrategy(MergeStrategy.RECURSIVE).call();
            }
            fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.MERGE_RESTART));
        } catch (IOException | NoRepositorySelected | GitAPIException e) {
            fireOperationFailed(new GitEventInfo(GitOperation.MERGE_RESTART), e);
            LOGGER.error(e.getMessage(), e);
        }
    });
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) Repository(org.eclipse.jgit.lib.Repository) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) SSHCapableUserCredentialsProvider(com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) IOException(java.io.IOException) RepositoryState(org.eclipse.jgit.lib.RepositoryState)

Example 5 with GitEventInfo

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

the class GitAccess method updateConfigFile.

/**
 * Updates the config file with new configurations.
 *
 * @throws NoRepositorySelected
 */
public void updateConfigFile() throws NoRepositorySelected {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.UPDATE_CONFIG_FILE));
    try {
        GitAccess.getInstance().getRepository().getConfig().save();
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
        fireOperationFailed(new GitEventInfo(GitOperation.UPDATE_CONFIG_FILE), e);
    }
    fireOperationSuccessfullyEnded(new GitEventInfo(GitOperation.UPDATE_CONFIG_FILE));
}
Also used : GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) IOException(java.io.IOException)

Aggregations

GitEventInfo (com.oxygenxml.git.view.event.GitEventInfo)23 WorkingCopyGitEventInfo (com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)19 BranchGitEventInfo (com.oxygenxml.git.view.event.BranchGitEventInfo)18 FileGitEventInfo (com.oxygenxml.git.view.event.FileGitEventInfo)18 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)11 IOException (java.io.IOException)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 StashApplyStatus (com.oxygenxml.git.view.stash.StashApplyStatus)3 ArrayList (java.util.ArrayList)3 CheckoutCommand (org.eclipse.jgit.api.CheckoutCommand)3 Repository (org.eclipse.jgit.lib.Repository)3 GitController (com.oxygenxml.git.view.event.GitController)2 GitOperation (com.oxygenxml.git.view.event.GitOperation)2 StashApplyFailureWithStatusException (com.oxygenxml.git.view.stash.StashApplyFailureWithStatusException)2 StashApplyFailureException (org.eclipse.jgit.api.errors.StashApplyFailureException)2 RevWalk (org.eclipse.jgit.revwalk.RevWalk)2 StandalonePluginWorkspace (ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)2 OxygenGitPluginExtension (com.oxygenxml.git.OxygenGitPluginExtension)1 SSHCapableUserCredentialsProvider (com.oxygenxml.git.auth.SSHCapableUserCredentialsProvider)1 GitEventAdapter (com.oxygenxml.git.service.GitEventAdapter)1