diff --git a/plugins/git4idea/src/git4idea/push/GitPushLog.java b/plugins/git4idea/src/git4idea/push/GitPushLog.java index 8c492ed2e770..9fc48df5fa12 100644 --- a/plugins/git4idea/src/git4idea/push/GitPushLog.java +++ b/plugins/git4idea/src/git4idea/push/GitPushLog.java @@ -371,7 +371,6 @@ class GitPushLog extends JPanel implements TypeSafeDataProvider { GitBranch dest = branchInfo.getDestBranch(); GitPushBranchInfo.Type type = branchInfo.getType(); - final String showingRecentCommits = ", showing " + GitPusher.RECENT_COMMITS_NUMBER + " recent commits"; String text = fromBranch.getName(); SimpleTextAttributes attrs = SimpleTextAttributes.REGULAR_ATTRIBUTES; String additionalText = ""; @@ -385,11 +384,11 @@ class GitPushLog extends JPanel implements TypeSafeDataProvider { case NEW_BRANCH: text += " -> +" + dest.getName(); attrs = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; - additionalText = " new branch will be created" + showingRecentCommits; + additionalText = " new branch will be created."; break; case NO_TRACKED_OR_TARGET: attrs = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; - additionalText = " no tracked branch. Use checkbox below to push branch to manually specified" + showingRecentCommits; + additionalText = " no tracked branch. Use checkbox below to push branch to manually specified."; break; } renderer.append(text, attrs); diff --git a/plugins/git4idea/src/git4idea/push/GitPusher.java b/plugins/git4idea/src/git4idea/push/GitPusher.java index 75f31576f6fe..e56d15c1b6c4 100644 --- a/plugins/git4idea/src/git4idea/push/GitPusher.java +++ b/plugins/git4idea/src/git4idea/push/GitPusher.java @@ -59,11 +59,6 @@ import java.util.concurrent.atomic.AtomicInteger; */ public final class GitPusher { - /** - * if diff-log is not available (new branch is created, for example), we show a few recent commits made on the branch - */ - static final int RECENT_COMMITS_NUMBER = 5; - @Deprecated static final GitRemoteBranch NO_TARGET_BRANCH = new GitStandardRemoteBranch(GitRemote.DOT, "", GitBranch.DUMMY_HASH); @@ -187,7 +182,7 @@ public final class GitPusher { List commits; GitPushBranchInfo.Type type; if (dest == NO_TARGET_BRANCH) { - commits = collectRecentCommitsOnBranch(repository, source); + commits = collectCommitsToPushForNewBranch(repository, source, dest.getRemote()); type = GitPushBranchInfo.Type.NO_TRACKED_OR_TARGET; } else if (GitUtil.repoContainsRemoteBranch(repository, dest)) { @@ -195,7 +190,7 @@ public final class GitPusher { type = GitPushBranchInfo.Type.STANDARD; } else { - commits = collectRecentCommitsOnBranch(repository, source); + commits = collectCommitsToPushForNewBranch(repository, source, dest.getRemote()); type = GitPushBranchInfo.Type.NEW_BRANCH; } commitsByBranch.put(source, new GitPushBranchInfo(source, dest, commits, type)); @@ -204,8 +199,13 @@ public final class GitPusher { return new GitCommitsByBranch(commitsByBranch); } - private List collectRecentCommitsOnBranch(GitRepository repository, GitBranch source) throws VcsException { - return GitHistoryUtils.history(myProject, repository.getRoot(), "--max-count=" + RECENT_COMMITS_NUMBER, source.getName()); + @NotNull + private static List collectCommitsToPushForNewBranch(@NotNull GitRepository repository, @NotNull GitBranch source, + @NotNull GitRemote remote) throws VcsException { + // `git log new_branch --not --remotes=origin` + // shows all commits that are in the given branch, but not in any remote branches in the given remote + return GitHistoryUtils.history(repository.getProject(), repository.getRoot(), + source.getName(), "--not", "--remotes=" + remote.getName()); } @NotNull