Search in sources :

Example 1 with GitCommit

use of git4idea.GitCommit in project intellij-community by JetBrains.

the class GitBranchWorker method loadCommitsToCompare.

@NotNull
private Couple<List<GitCommit>> loadCommitsToCompare(@NotNull GitRepository repository, @NotNull final String branchName) {
    final List<GitCommit> headToBranch;
    final List<GitCommit> branchToHead;
    try {
        headToBranch = GitHistoryUtils.history(myProject, repository.getRoot(), ".." + branchName);
        branchToHead = GitHistoryUtils.history(myProject, repository.getRoot(), branchName + "..");
    } catch (VcsException e) {
        // we treat it as critical and report an error
        throw new GitExecutionException("Couldn't get [git log .." + branchName + "] on repository [" + repository.getRoot() + "]", e);
    }
    return Couple.of(headToBranch, branchToHead);
}
Also used : GitCommit(git4idea.GitCommit) GitExecutionException(git4idea.GitExecutionException) VcsException(com.intellij.openapi.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GitCommit

use of git4idea.GitCommit in project intellij-community by JetBrains.

the class GitOutgoingCommitsProvider method getOutgoingCommits.

@NotNull
@Override
public OutgoingResult getOutgoingCommits(@NotNull GitRepository repository, @NotNull PushSpec<GitPushSource, GitPushTarget> pushSpec, boolean initial) {
    GitLocalBranch branch = pushSpec.getSource().getBranch();
    String source = branch.equals(repository.getCurrentBranch()) ? HEAD : branch.getFullName();
    GitPushTarget target = pushSpec.getTarget();
    String destination = target.getBranch().getFullName();
    try {
        List<GitCommit> commits;
        if (!target.isNewBranchCreated()) {
            commits = GitHistoryUtils.history(myProject, repository.getRoot(), destination + ".." + source);
        } else {
            commits = GitHistoryUtils.history(myProject, repository.getRoot(), source, "--not", "--remotes=" + target.getBranch().getRemote().getName(), "--max-count=" + 1000);
        }
        return new OutgoingResult(commits, Collections.<VcsError>emptyList());
    } catch (VcsException e) {
        return new OutgoingResult(Collections.<VcsFullCommitDetails>emptyList(), Collections.singletonList(new VcsError(GitUtil.cleanupErrorPrefixes(e.getMessage()))));
    }
}
Also used : GitLocalBranch(git4idea.GitLocalBranch) GitCommit(git4idea.GitCommit) VcsException(com.intellij.openapi.vcs.VcsException) OutgoingResult(com.intellij.dvcs.push.OutgoingResult) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails) VcsError(com.intellij.dvcs.push.VcsError) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitCommit

use of git4idea.GitCommit in project intellij-community by JetBrains.

the class GitCommitListPanel method calcData.

// Make changes available for diff action
@Override
public void calcData(DataKey key, DataSink sink) {
    if (VcsDataKeys.CHANGES.equals(key)) {
        int[] rows = myTable.getSelectedRows();
        if (rows.length != 1)
            return;
        int row = rows[0];
        GitCommit gitCommit = myCommits.get(row);
        // suppressing: inherited API
        //noinspection unchecked
        sink.put(key, ArrayUtil.toObjectArray(gitCommit.getChanges(), Change.class));
    }
}
Also used : GitCommit(git4idea.GitCommit) Change(com.intellij.openapi.vcs.changes.Change)

Example 4 with GitCommit

use of git4idea.GitCommit in project intellij-community by JetBrains.

the class GithubCreatePullRequestWorker method doLoadDiffInfo.

@NotNull
private DiffInfo doLoadDiffInfo(@NotNull final BranchInfo branch) throws VcsException {
    // TODO: make cancelable and abort old speculative requests (when git4idea will allow to do so)
    String currentBranch = myCurrentBranch;
    String targetBranch = branch.getForkInfo().getRemoteName() + "/" + branch.getRemoteName();
    List<GitCommit> commits1 = GitHistoryUtils.history(myProject, myGitRepository.getRoot(), ".." + targetBranch);
    List<GitCommit> commits2 = GitHistoryUtils.history(myProject, myGitRepository.getRoot(), targetBranch + "..");
    Collection<Change> diff = GitChangeUtils.getDiff(myProject, myGitRepository.getRoot(), targetBranch, myCurrentBranch, null);
    GitCommitCompareInfo info = new GitCommitCompareInfo(GitCommitCompareInfo.InfoType.BRANCH_TO_HEAD);
    info.put(myGitRepository, diff);
    info.put(myGitRepository, Couple.of(commits1, commits2));
    return new DiffInfo(info, currentBranch, targetBranch);
}
Also used : GitCommitCompareInfo(git4idea.util.GitCommitCompareInfo) GitCommit(git4idea.GitCommit) Change(com.intellij.openapi.vcs.changes.Change) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GitCommit

use of git4idea.GitCommit in project intellij-community by JetBrains.

the class GitCommitListPanel method generateColumnsInfo.

@NotNull
private ColumnInfo[] generateColumnsInfo(@NotNull List<GitCommit> commits) {
    ItemAndWidth hash = new ItemAndWidth("", 0);
    ItemAndWidth author = new ItemAndWidth("", 0);
    ItemAndWidth time = new ItemAndWidth("", 0);
    for (GitCommit commit : commits) {
        hash = getMax(hash, getHash(commit));
        author = getMax(author, getAuthor(commit));
        time = getMax(time, getTime(commit));
    }
    return new ColumnInfo[] { new GitCommitColumnInfo("Hash", hash.myItem) {

        @Override
        public String valueOf(GitCommit commit) {
            return getHash(commit);
        }
    }, new ColumnInfo<GitCommit, String>("Subject") {

        @Override
        public String valueOf(GitCommit commit) {
            return commit.getSubject();
        }
    }, new GitCommitColumnInfo("Author", author.myItem) {

        @Override
        public String valueOf(GitCommit commit) {
            return getAuthor(commit);
        }
    }, new GitCommitColumnInfo("Author time", time.myItem) {

        @Override
        public String valueOf(GitCommit commit) {
            return getTime(commit);
        }
    } };
}
Also used : GitCommit(git4idea.GitCommit) ColumnInfo(com.intellij.util.ui.ColumnInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitCommit (git4idea.GitCommit)5 NotNull (org.jetbrains.annotations.NotNull)4 VcsException (com.intellij.openapi.vcs.VcsException)2 Change (com.intellij.openapi.vcs.changes.Change)2 OutgoingResult (com.intellij.dvcs.push.OutgoingResult)1 VcsError (com.intellij.dvcs.push.VcsError)1 ColumnInfo (com.intellij.util.ui.ColumnInfo)1 VcsFullCommitDetails (com.intellij.vcs.log.VcsFullCommitDetails)1 GitExecutionException (git4idea.GitExecutionException)1 GitLocalBranch (git4idea.GitLocalBranch)1 GitCommitCompareInfo (git4idea.util.GitCommitCompareInfo)1