git: restore the old Compare with Current dialog: IDEA-216382

Users miss the ability to view both sides of the comparison in a single view. This problem is not solved yet => the old view is returned for the 2020.1 release.

This commit is a modified cherry-pick of b432f0f5e5159d745f1569ef68cde1fbba2d5b52 and a revert of 4de067449eabf6a554c8d905d76668225cd5dff6 and 7c3b3f63024bac8aa62638b06c0aa35e9874f3a7

See also IDEA-CR-53852

GitOrigin-RevId: 22ab2d751e4e9cf57e1db83c6aa2309fa6324257
This commit is contained in:
Kirill Likhodedov
2020-03-30 14:31:51 +00:00
committed by intellij-monorepo-bot
parent 58b9be5c13
commit ff7ec062b6
7 changed files with 89 additions and 55 deletions
@@ -1225,6 +1225,8 @@ git.force.commit.using.staging.area=true
git.force.commit.using.staging.area.description=When enabled, perform all git commits by updating staging area. If disabled, use `git commit --only` when possible.
git.clone.recurse.submodules=true
git.clone.recurse.submodules.description=When enabled, Checkout from Git calls `git clone --recurse-submodules`, i.e. clones the main repository with all submodules if there are any.
git.compare.branches.as.tab=false
git.compare.branches.as.tab.description=Compares branches by showing a log tab filtered by `HEAD..branch` instead of showing a dialog.
git.read.content.with.textconv=false
git.read.content.with.textconv.description=Apply `textconv` transformations when reading file content from git. (overrides "git.read.content.with.filters" option)
git.read.content.with.filters=true
@@ -775,6 +775,10 @@ branch.checking.out.new.branch.process=Checking out new branch {0}...
branch.creating.branch.process=Creating branch {0}...
branch.checking.out.branch.from.process=Checking out {0} from {1}...
branch.checking.out.process=Checking out {0}...
branch.compare.progress=Comparing with {0}...
compare.branches.error=Can't Compare with Branch
compare.branches.no.changes.message.title=No Changes Detected
compare.branches.no.changes.message.description=<html>There are no changes between <code>{0}</code> and <code>{1}</code></html>
branch.not.fully.merged.dialog.repository.label=Repository:
branch.not.fully.merged.dialog.title=Branch Was Not Fully Merged
@@ -794,4 +798,4 @@ show.diff.between.dialog.could.not.load.diff.with.branch.error=Couldn''t load di
annotations.options.detect.movements.across.files=Detect Movements Across Files
annotations.options.detect.movements.within.file=Detect Movements Within File
annotations.options.ignore.whitespaces=Ignore Whitespaces
annotations.options.group=Options
annotations.options.group=Options
@@ -1,27 +1,18 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package git4idea.branch;
import com.intellij.dvcs.repo.Repository;
import com.intellij.dvcs.ui.CompareBranchesDialog;
import com.intellij.dvcs.util.CommitCompareInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.VcsNotifier;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.util.containers.ContainerUtil;
import git4idea.GitCommit;
import git4idea.GitLocalBranch;
import git4idea.GitUtil;
import git4idea.GitVcs;
@@ -29,8 +20,11 @@ import git4idea.changes.GitChangeUtils;
import git4idea.commands.Git;
import git4idea.commands.GitCommandResult;
import git4idea.i18n.GitBundle;
import git4idea.history.GitHistoryUtils;
import git4idea.rebase.GitRebaseUtils;
import git4idea.repo.GitRepository;
import git4idea.ui.branch.GitCompareBranchesHelper;
import git4idea.util.GitLocalCommitCompareInfo;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -166,12 +160,49 @@ public final class GitBranchWorker {
new GitRenameBranchOperation(myProject, myGit, myUiHandler, currentName, newName, repositories).execute();
}
void compare(@NotNull String branchName, @NotNull List<? extends GitRepository> repositories, @NotNull GitRepository selectedRepository) {
try {
CommitCompareInfo myCompareInfo = loadCommitsToCompare(repositories, branchName);
ApplicationManager.getApplication().invokeLater(
() -> displayCompareDialog(branchName, GitBranchUtil.getCurrentBranchOrRev(repositories), myCompareInfo, selectedRepository));
}
catch (VcsException e) {
VcsNotifier.getInstance(myProject).notifyError(GitBundle.message("compare.branches.error"), e.getMessage());
}
}
@NotNull
private CommitCompareInfo loadCommitsToCompare(@NotNull List<? extends GitRepository> repositories,
@NotNull String branchName) throws VcsException {
CommitCompareInfo compareInfo = new GitLocalCommitCompareInfo(myProject, branchName);
for (GitRepository repository : repositories) {
List<GitCommit> headToBranch = GitHistoryUtils.history(myProject, repository.getRoot(), ".." + branchName);
List<GitCommit> branchToHead = GitHistoryUtils.history(myProject, repository.getRoot(), branchName + "..");
compareInfo.put(repository, headToBranch, branchToHead);
compareInfo.putTotalDiff(repository, loadTotalDiff(repository, branchName));
}
return compareInfo;
}
@NotNull
public static Collection<Change> loadTotalDiff(@NotNull Repository repository, @NotNull String branchName) throws VcsException {
// return git diff between current working directory and branchName: working dir should be displayed as a 'left' one (base)
return GitChangeUtils.getDiffWithWorkingDir(repository.getProject(), repository.getRoot(), branchName, null, true);
}
private void displayCompareDialog(@NotNull String branchName, @NotNull String currentBranch, @NotNull CommitCompareInfo compareInfo,
@NotNull GitRepository selectedRepository) {
if (compareInfo.isEmpty()) {
Messages.showInfoMessage(myProject, GitBundle.message("compare.branches.no.changes.message.description", currentBranch, branchName),
GitBundle.message("compare.branches.no.changes.message.title"));
}
else {
new CompareBranchesDialog(new GitCompareBranchesHelper(myProject),
branchName, currentBranch, compareInfo, selectedRepository, false).show();
}
}
private static void updateInfo(@NotNull Collection<? extends GitRepository> repositories) {
for (GitRepository repository : repositories) {
repository.update();
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package git4idea.branch;
import com.intellij.openapi.components.ServiceManager;
@@ -156,7 +142,9 @@ public interface GitBrancher {
/**
* Compares commits from the HEAD with the specified branch.
*/
void compare(@NotNull String branchName, @NotNull List<? extends GitRepository> repositories);
void compare(@NotNull String branchName,
@NotNull List<? extends GitRepository> repositories,
@NotNull GitRepository selectedRepository);
/**
* Compares the current working tree with its state in the selected branch.
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package git4idea.branch;
import com.intellij.openapi.application.Application;
@@ -21,6 +7,7 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.util.registry.Registry;
import git4idea.GitVcs;
import git4idea.commands.Git;
import git4idea.i18n.GitBundle;
@@ -158,8 +145,20 @@ class GitBrancherImpl implements GitBrancher {
}
@Override
public void compare(@NotNull String branchName, @NotNull List<? extends GitRepository> repositories) {
new GitCompareBranchesUi(myProject, repositories, branchName).create();
public void compare(@NotNull String branchName,
@NotNull List<? extends GitRepository> repositories,
@NotNull GitRepository selectedRepository) {
if (Registry.is("git.compare.branches.as.tab")) {
new GitCompareBranchesUi(myProject, repositories, branchName).create();
}
else {
new CommonBackgroundTask(myProject, GitBundle.message("branch.compare.progress", branchName), null) {
@Override
public void execute(@NotNull ProgressIndicator indicator) {
newWorker(indicator).compare(branchName, repositories, selectedRepository);
}
}.runInBackground();
}
}
@Override
@@ -270,7 +270,7 @@ public class GitBranchPopupActions {
new CheckoutAsNewBranch(myProject, myRepositories, myBranchName),
new CheckoutWithRebaseAction(myProject, myRepositories, myBranchName),
new Separator(),
new CompareAction(myProject, myRepositories, myBranchName),
new CompareAction(myProject, myRepositories, myBranchName, mySelectedRepository),
new ShowDiffWithBranchAction(myProject, myRepositories, myBranchName),
new Separator(),
new RebaseAction(myProject, myRepositories, myBranchName),
@@ -480,7 +480,7 @@ public class GitBranchPopupActions {
new CheckoutRemoteBranchAction(myProject, myRepositories, myBranchName),
new CheckoutAsNewBranch(myProject, myRepositories, myBranchName),
new Separator(),
new CompareAction(myProject, myRepositories, myBranchName),
new CompareAction(myProject, myRepositories, myBranchName, mySelectedRepository),
new ShowDiffWithBranchAction(myProject, myRepositories, myBranchName),
new Separator(),
new RebaseAction(myProject, myRepositories, myBranchName),
@@ -619,12 +619,17 @@ public class GitBranchPopupActions {
private final Project myProject;
private final List<? extends GitRepository> myRepositories;
private final String myBranchName;
private final GitRepository mySelectedRepository;
CompareAction(@NotNull Project project, @NotNull List<? extends GitRepository> repositories, @NotNull String branchName) {
CompareAction(@NotNull Project project,
@NotNull List<? extends GitRepository> repositories,
@NotNull String branchName,
@NotNull GitRepository selectedRepository) {
super(GitBundle.messagePointer("branches.compare.with.current"));
myProject = project;
myRepositories = repositories;
myBranchName = branchName;
mySelectedRepository = selectedRepository;
}
@Override
@@ -632,7 +637,7 @@ public class GitBranchPopupActions {
FileDocumentManager.getInstance().saveAllDocuments();
GitBrancher brancher = GitBrancher.getInstance(myProject);
brancher.compare(myBranchName, myRepositories);
brancher.compare(myBranchName, myRepositories, mySelectedRepository);
}
@Override
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package git4idea.ui.branch.dashboard
import com.intellij.dvcs.DvcsUtil
@@ -18,6 +18,7 @@ import com.intellij.vcs.log.ui.VcsLogInternalDataKeys
import git4idea.GitUtil
import git4idea.actions.GitFetch
import git4idea.branch.GitBranchType
import git4idea.branch.GitBranchUtil
import git4idea.branch.GitBrancher
import git4idea.config.GitVcsSettings
import git4idea.fetch.GitFetchResult
@@ -200,15 +201,19 @@ internal object BranchesDashboardActions {
e.presentation.isEnabled = false
e.presentation.description = message("action.Git.Update.Selected.description.select.non.current")
}
else if (GitBranchUtil.getCurrentRepository(project) == null) {
e.presentation.isEnabled = false
}
}
override fun actionPerformed(e: AnActionEvent) {
val branches = e.getData(GIT_BRANCHES)!!
val project = e.project!!
val gitBrancher = GitBrancher.getInstance(project)
val currentRepository = GitBranchUtil.getCurrentRepository(project)!!
for (branch in branches.filterNot(BranchInfo::isCurrent)) {
gitBrancher.compare(branch.branchName, branch.repositories)
gitBrancher.compare(branch.branchName, branch.repositories, currentRepository)
}
}
}