Search in sources :

Example 6 with RepositoryState

use of org.eclipse.jgit.lib.RepositoryState in project egit by eclipse.

the class RevUtils method getConflictCommits.

/**
 * @param repository
 * @param path
 *            repository-relative path of file with conflicts
 * @return an object with the interesting commits for this path
 * @throws IOException
 */
public static ConflictCommits getConflictCommits(Repository repository, String path) throws IOException {
    try (RevWalk walk = new RevWalk(repository)) {
        RevCommit ourCommit;
        RevCommit theirCommit = null;
        walk.setTreeFilter(AndTreeFilter.create(PathFilterGroup.createFromStrings(path), TreeFilter.ANY_DIFF));
        RevCommit head = walk.parseCommit(repository.resolve(Constants.HEAD));
        walk.markStart(head);
        ourCommit = walk.next();
        RepositoryState state = repository.getRepositoryState();
        if (state == RepositoryState.REBASING || state == RepositoryState.CHERRY_PICKING) {
            ObjectId cherryPickHead = repository.readCherryPickHead();
            if (cherryPickHead != null) {
                RevCommit cherryPickCommit = walk.parseCommit(cherryPickHead);
                theirCommit = cherryPickCommit;
            }
        } else if (state == RepositoryState.MERGING) {
            List<ObjectId> mergeHeads = repository.readMergeHeads();
            Assert.isNotNull(mergeHeads);
            if (mergeHeads.size() == 1) {
                ObjectId mergeHead = mergeHeads.get(0);
                RevCommit mergeCommit = walk.parseCommit(mergeHead);
                walk.reset();
                walk.markStart(mergeCommit);
                theirCommit = walk.next();
            }
        }
        return new ConflictCommits(ourCommit, theirCommit);
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) List(java.util.List) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RepositoryState(org.eclipse.jgit.lib.RepositoryState) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 7 with RepositoryState

use of org.eclipse.jgit.lib.RepositoryState in project egit by eclipse.

the class CommitHelper method calculateCommitInfo.

private void calculateCommitInfo() {
    Repository mergeRepository = null;
    isMergedResolved = false;
    isCherryPickResolved = false;
    RepositoryState state = repository.getRepositoryState();
    canCommit = state.canCommit();
    if (!canCommit) {
        cannotCommitMessage = NLS.bind(UIText.CommitAction_repositoryState, state.getDescription());
        return;
    }
    if (state.equals(RepositoryState.MERGING_RESOLVED)) {
        isMergedResolved = true;
        mergeRepository = repository;
    } else if (state.equals(RepositoryState.CHERRY_PICKING_RESOLVED)) {
        isCherryPickResolved = true;
        mergeRepository = repository;
    }
    previousCommit = getHeadCommit(repository);
    final UserConfig config = repository.getConfig().get(UserConfig.KEY);
    author = config.getAuthorName();
    final String authorEmail = config.getAuthorEmail();
    // $NON-NLS-1$ //$NON-NLS-2$
    author = author + " <" + authorEmail + ">";
    committer = config.getCommitterName();
    final String committerEmail = config.getCommitterEmail();
    // $NON-NLS-1$ //$NON-NLS-2$
    committer = committer + " <" + committerEmail + ">";
    if (isMergedResolved || isCherryPickResolved) {
        commitMessage = getMergeResolveMessage(mergeRepository);
    }
    if (isCherryPickResolved) {
        author = getCherryPickOriginalAuthor(mergeRepository);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryState(org.eclipse.jgit.lib.RepositoryState) UserConfig(org.eclipse.jgit.lib.UserConfig)

Example 8 with RepositoryState

use of org.eclipse.jgit.lib.RepositoryState in project egit by eclipse.

the class ReflogView method getRepositoryName.

private static String getRepositoryName(Repository repository) {
    String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
    RepositoryState state = repository.getRepositoryState();
    if (state != RepositoryState.SAFE)
        return repoName + '|' + state.getDescription();
    else
        return repoName;
}
Also used : RepositoryState(org.eclipse.jgit.lib.RepositoryState)

Example 9 with RepositoryState

use of org.eclipse.jgit.lib.RepositoryState in project egit by eclipse.

the class RebaseActionHandler method isEnabled.

@Override
public boolean isEnabled() {
    Repository repo = getRepository();
    if (repo == null)
        return false;
    // Either we want this to be enabled because a new rebase can be started
    // (main action) or an active rebase can be continued, skipped or
    // aborted (menu items). Even when the main action is not enabled we
    // must enable this because otherwise the menu items cannot be opened.
    RepositoryState state = repo.getRepositoryState();
    return state.isRebasing() || RebaseCurrentRefCommand.isEnabledForState(repo, state);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryState(org.eclipse.jgit.lib.RepositoryState)

Aggregations

RepositoryState (org.eclipse.jgit.lib.RepositoryState)9 List (java.util.List)2 GitUser (org.eclipse.che.api.git.shared.GitUser)2 Repository (org.eclipse.jgit.lib.Repository)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Files (com.google.common.io.Files)1 JSch (com.jcraft.jsch.JSch)1 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 System.lineSeparator (java.lang.System.lineSeparator)1 URISyntaxException (java.net.URISyntaxException)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1 OWNER_READ (java.nio.file.attribute.PosixFilePermission.OWNER_READ)1