Search in sources :

Example 1 with BranchGitEventInfo

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

the class GitAccess method createBranch.

/**
 * Creates a new branch in the repository
 *
 * @param branchName   - Name for the new branch
 * @param sourceCommit - The commit source.
 */
public void createBranch(String branchName, String sourceCommit) {
    try {
        fireOperationAboutToStart(new BranchGitEventInfo(GitOperation.CREATE_BRANCH, branchName));
        git.branchCreate().setName(branchName).setStartPoint(sourceCommit).call();
        fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.CREATE_BRANCH, branchName));
    } catch (GitAPIException e) {
        fireOperationFailed(new BranchGitEventInfo(GitOperation.CREATE_BRANCH, branchName), e);
        PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(e.getMessage(), e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo)

Example 2 with BranchGitEventInfo

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

the class GitAccess method createBranchFromLocalBranch.

/**
 * Creates a new local branch in the current repository, starting from another local branch.
 *
 * @param newBranchName The name for the new branch.
 * @param sourceBranch The full path for the local branch from which to create the new branch.
 *
 * @throws GitAPIException
 */
public void createBranchFromLocalBranch(String newBranchName, String sourceBranch) throws GitAPIException {
    fireOperationAboutToStart(new BranchGitEventInfo(GitOperation.CREATE_BRANCH, newBranchName));
    try {
        git.branchCreate().setName(newBranchName).setStartPoint(sourceBranch).call();
        fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.CREATE_BRANCH, newBranchName));
    } catch (GitAPIException e) {
        fireOperationFailed(new BranchGitEventInfo(GitOperation.CREATE_BRANCH, newBranchName), e);
        throw e;
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo)

Example 3 with BranchGitEventInfo

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

the class GitAccess method checkoutCommitAndCreateBranch.

/**
 * Check out a specific commit and create a branch with it.
 *
 * @param branchName The name of the new branch.
 * @param commitID   The ID of the commit to be checked-out as a new branch.
 *
 * @throws GitAPIException
 */
public void checkoutCommitAndCreateBranch(String branchName, String commitID) throws GitAPIException {
    fireOperationAboutToStart(new BranchGitEventInfo(GitOperation.CHECKOUT, branchName));
    try {
        git.checkout().setCreateBranch(true).setName(branchName).setStartPoint(commitID).call();
        fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.CHECKOUT, branchName));
    } catch (GitAPIException e) {
        fireOperationFailed(new BranchGitEventInfo(GitOperation.CHECKOUT, branchName), e);
        throw e;
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo)

Example 4 with BranchGitEventInfo

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

the class GitAccess method createStash.

/**
 * Create a new stash command.
 *
 * @param includeUntrackedFiles <code>True</code> if the stash should include the untracked files.
 * @param description           The description of stash. May be <code>null</code>.
 *
 * @return The created stash.
 */
public RevCommit createStash(boolean includeUntrackedFiles, String description) {
    fireOperationAboutToStart(new GitEventInfo(GitOperation.STASH_CREATE));
    RevCommit stash = null;
    try {
        StashCreateCommand createStashCmd = git.stashCreate().setIncludeUntracked(includeUntrackedFiles);
        if (description != null) {
            createStashCmd.setWorkingDirectoryMessage(description);
        }
        stash = createStashCmd.call();
        fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.STASH_CREATE, getBranchInfo().getBranchName()));
    } catch (GitAPIException e) {
        if (repositoryHasConflicts()) {
            PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(TRANSLATOR.getTranslation(Tags.RESOLVE_CONFLICTS_FIRST));
        } else {
            PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(TRANSLATOR.getTranslation(Tags.STASH_CANNOT_BE_CREATED) + e.getMessage(), e);
            LOGGER.error(e.getMessage(), e);
        }
        fireOperationFailed(new BranchGitEventInfo(GitOperation.STASH_CREATE, getBranchInfo().getBranchName()), e);
    }
    return stash;
}
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) StashCreateCommand(org.eclipse.jgit.api.StashCreateCommand) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with BranchGitEventInfo

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

the class GitAccess method setBranch.

/**
 * Sets the given branch as the current branch
 *
 * @param branch The short name of the branch to set.
 *
 * @throws GitAPIException
 */
public void setBranch(String branch) throws GitAPIException {
    fireOperationAboutToStart(new BranchGitEventInfo(GitOperation.CHECKOUT, branch));
    try {
        git.checkout().setName(branch).call();
        fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.CHECKOUT, branch));
    } catch (GitAPIException e) {
        fireOperationFailed(new BranchGitEventInfo(GitOperation.CHECKOUT, branch), e);
        throw e;
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchGitEventInfo(com.oxygenxml.git.view.event.BranchGitEventInfo)

Aggregations

BranchGitEventInfo (com.oxygenxml.git.view.event.BranchGitEventInfo)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)7 WorkingCopyGitEventInfo (com.oxygenxml.git.view.event.WorkingCopyGitEventInfo)2 FileGitEventInfo (com.oxygenxml.git.view.event.FileGitEventInfo)1 GitEventInfo (com.oxygenxml.git.view.event.GitEventInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 DeleteBranchCommand (org.eclipse.jgit.api.DeleteBranchCommand)1 MergeCommand (org.eclipse.jgit.api.MergeCommand)1 MergeResult (org.eclipse.jgit.api.MergeResult)1 StashCreateCommand (org.eclipse.jgit.api.StashCreateCommand)1 CheckoutConflictException (org.eclipse.jgit.api.errors.CheckoutConflictException)1 RevisionSyntaxException (org.eclipse.jgit.errors.RevisionSyntaxException)1 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1