mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git: replace '--preserve-merges' with '--rebase -merges' for Git >= 2.22: IDEA-216247
Not only the parameter became deprecated, but also a custom core.commentChar is not supported with '--preserve-merges' anymore. GitOrigin-RevId: 24c336e752935cbbc69cb91f50d02dfc943c0669
This commit is contained in:
committed by
intellij-monorepo-bot
parent
59dc540043
commit
b719e2241d
@@ -22,6 +22,7 @@ import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import git4idea.GitLocalBranch;
|
||||
import git4idea.GitVcs;
|
||||
import git4idea.changes.GitChangeUtils;
|
||||
import git4idea.commands.Git;
|
||||
import git4idea.rebase.GitRebaseUtils;
|
||||
@@ -44,11 +45,13 @@ public final class GitBranchWorker {
|
||||
@NotNull private final Project myProject;
|
||||
@NotNull private final Git myGit;
|
||||
@NotNull private final GitBranchUiHandler myUiHandler;
|
||||
@NotNull private final GitVcs myVcs;
|
||||
|
||||
public GitBranchWorker(@NotNull Project project, @NotNull Git git, @NotNull GitBranchUiHandler uiHandler) {
|
||||
myProject = project;
|
||||
myGit = git;
|
||||
myUiHandler = uiHandler;
|
||||
myVcs = GitVcs.getInstance(myProject);
|
||||
}
|
||||
|
||||
public void checkoutNewBranch(@NotNull final String name, @NotNull List<? extends GitRepository> repositories) {
|
||||
@@ -117,12 +120,12 @@ public final class GitBranchWorker {
|
||||
|
||||
public void rebase(@NotNull List<? extends GitRepository> repositories, @NotNull String branchName) {
|
||||
updateInfo(repositories);
|
||||
GitRebaseUtils.rebase(myProject, repositories, new GitRebaseParams(branchName), myUiHandler.getProgressIndicator());
|
||||
GitRebaseUtils.rebase(myProject, repositories, new GitRebaseParams(myVcs.getVersion(), branchName), myUiHandler.getProgressIndicator());
|
||||
}
|
||||
|
||||
public void rebaseOnCurrent(@NotNull List<? extends GitRepository> repositories, @NotNull String branchName) {
|
||||
updateInfo(repositories);
|
||||
GitRebaseUtils.rebase(myProject, repositories, new GitRebaseParams(branchName, null, "HEAD", false, false),
|
||||
GitRebaseUtils.rebase(myProject, repositories, new GitRebaseParams(myVcs.getVersion(), branchName, null, "HEAD", false, false),
|
||||
myUiHandler.getProgressIndicator());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// 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.
|
||||
package git4idea.branch
|
||||
|
||||
import git4idea.config.GitVersion
|
||||
import git4idea.config.GitVersionSpecialty
|
||||
import git4idea.rebase.GitRebaseEditorHandler
|
||||
|
||||
class GitRebaseParams private constructor(branch: String?,
|
||||
class GitRebaseParams private constructor(private val version: GitVersion,
|
||||
branch: String?,
|
||||
newBase: String?,
|
||||
val upstream: String,
|
||||
val interactive: Boolean,
|
||||
@@ -11,11 +14,12 @@ class GitRebaseParams private constructor(branch: String?,
|
||||
private val autoSquash: AutoSquashOption,
|
||||
val editorHandler: GitRebaseEditorHandler? = null) {
|
||||
companion object {
|
||||
fun editCommits(base: String,
|
||||
fun editCommits(version: GitVersion,
|
||||
base: String,
|
||||
editorHandler: GitRebaseEditorHandler?,
|
||||
preserveMerges: Boolean,
|
||||
autoSquash: AutoSquashOption = AutoSquashOption.DEFAULT): GitRebaseParams =
|
||||
GitRebaseParams(null, null, base, true, preserveMerges, autoSquash, editorHandler)
|
||||
GitRebaseParams(version, null, null, base, true, preserveMerges, autoSquash, editorHandler)
|
||||
}
|
||||
|
||||
enum class AutoSquashOption {
|
||||
@@ -27,20 +31,26 @@ class GitRebaseParams private constructor(branch: String?,
|
||||
val branch: String? = branch?.takeIf { it.isNotBlank() }
|
||||
val newBase: String? = newBase?.takeIf { it.isNotBlank() }
|
||||
|
||||
constructor(upstream: String) : this(null, null, upstream, false, false)
|
||||
constructor(version: GitVersion, upstream: String) : this(version, null, null, upstream, false, false)
|
||||
|
||||
constructor(branch: String?,
|
||||
constructor(version: GitVersion,
|
||||
branch: String?,
|
||||
newBase: String?,
|
||||
upstream: String,
|
||||
interactive: Boolean,
|
||||
preserveMerges: Boolean) : this(branch, newBase, upstream, interactive, preserveMerges, AutoSquashOption.DEFAULT)
|
||||
preserveMerges: Boolean) : this(version, branch, newBase, upstream, interactive, preserveMerges, AutoSquashOption.DEFAULT)
|
||||
|
||||
fun asCommandLineArguments(): List<String> = mutableListOf<String>().apply {
|
||||
if (interactive) {
|
||||
add("--interactive")
|
||||
}
|
||||
if (preserveMerges) {
|
||||
add("--preserve-merges")
|
||||
if (GitVersionSpecialty.REBASE_MERGES_REPLACES_PRESERVE_MERGES.existsIn(version)) {
|
||||
add("--rebase-merges")
|
||||
}
|
||||
else {
|
||||
add("--preserve-merges")
|
||||
}
|
||||
}
|
||||
when (autoSquash) {
|
||||
AutoSquashOption.DEFAULT -> {
|
||||
|
||||
@@ -22,8 +22,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* }
|
||||
* }</pre>
|
||||
* </p>
|
||||
*
|
||||
* @author Kirill Likhodedov
|
||||
*/
|
||||
public enum GitVersionSpecialty {
|
||||
|
||||
@@ -243,6 +241,13 @@ public enum GitVersionSpecialty {
|
||||
public boolean existsIn(@NotNull GitVersion version) {
|
||||
return version.isLaterOrEqual(new GitVersion(2, 2, 0, 0));
|
||||
}
|
||||
},
|
||||
|
||||
REBASE_MERGES_REPLACES_PRESERVE_MERGES {
|
||||
@Override
|
||||
public boolean existsIn(@NotNull GitVersion version) {
|
||||
return version.isLaterOrEqual(new GitVersion(2, 22, 0, 0));
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean existsIn(@NotNull GitVersion version);
|
||||
|
||||
@@ -33,7 +33,7 @@ class GitInteractiveRebaseAction : GitCommitEditingAction() {
|
||||
|
||||
object : Task.Backgroundable(project, "Rebasing") {
|
||||
override fun run(indicator: ProgressIndicator) {
|
||||
val params = GitRebaseParams.editCommits(commit.parents.first().asString(), null, false)
|
||||
val params = GitRebaseParams.editCommits(repository.vcs.version, commit.parents.first().asString(), null, false)
|
||||
GitRebaseUtils.rebase(project, listOf(repository), params, indicator);
|
||||
}
|
||||
}.queue()
|
||||
|
||||
@@ -26,7 +26,7 @@ class GitRebaseCheckinHandlerFactory : VcsCheckinHandlerFactory(GitVcs.getKey())
|
||||
if (!active) return
|
||||
object : Task.Backgroundable(project, "Rebasing") {
|
||||
override fun run(indicator: ProgressIndicator) {
|
||||
val params = GitRebaseParams.editCommits(rebaseFrom, null, false)
|
||||
val params = GitRebaseParams.editCommits(repository.vcs.version, rebaseFrom, null, false)
|
||||
GitRebaseUtils.rebase(project, listOf(repository), params, indicator)
|
||||
}
|
||||
}.queue()
|
||||
|
||||
@@ -404,7 +404,8 @@ public class GitRebaseDialog extends DialogWrapper {
|
||||
newBase = onto;
|
||||
}
|
||||
|
||||
return new GitRebaseParams(branch, newBase, upstream, myInteractiveCheckBox.isSelected(), myPreserveMergesCheckBox.isSelected());
|
||||
return new GitRebaseParams(GitVcs.getInstance(myProject).getVersion(),
|
||||
branch, newBase, upstream, myInteractiveCheckBox.isSelected(), myPreserveMergesCheckBox.isSelected());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -76,7 +76,8 @@ class GitRewordOperation(private val repository: GitRepository,
|
||||
entriesEditor = { list -> injectRewordAction(list) },
|
||||
plainTextEditor = { editorText -> supplyNewMessage(editorText) })
|
||||
|
||||
val params = GitRebaseParams.editCommits(commit.parents.first().asString(), rebaseEditor, true,
|
||||
val params = GitRebaseParams.editCommits(repository.vcs.version,
|
||||
commit.parents.first().asString(), rebaseEditor, true,
|
||||
GitRebaseParams.AutoSquashOption.DISABLE)
|
||||
val indicator = ProgressManager.getInstance().progressIndicator ?: EmptyProgressIndicator()
|
||||
val spec = GitRebaseSpec.forNewRebase(project, params, listOf(repository), indicator)
|
||||
|
||||
@@ -98,7 +98,7 @@ abstract class GitMergeProviderTestCase : GitPlatformTest() {
|
||||
else s.replace("pick", "reword")
|
||||
}.joinToString(LineSeparator.getSystemLineSeparator().separatorString)
|
||||
}, null))
|
||||
val rebaseParams = GitRebaseParams(null, null, "branch-$onto", true, false)
|
||||
val rebaseParams = GitRebaseParams(vcs.version, null, null, "branch-$onto", true, false)
|
||||
git.rebase(repository, rebaseParams)
|
||||
}
|
||||
|
||||
|
||||
@@ -263,7 +263,7 @@ class GitMultiRepoRebaseTest : GitRebaseBaseTest() {
|
||||
}
|
||||
|
||||
private fun rebase(onto: String) {
|
||||
GitTestingRebaseProcess(project, GitRebaseParams(onto), allRepositories).rebase()
|
||||
GitTestingRebaseProcess(project, GitRebaseParams(vcs.version, onto), allRepositories).rebase()
|
||||
}
|
||||
|
||||
private fun abortOngoingRebase() {
|
||||
|
||||
@@ -443,7 +443,7 @@ class GitSingleRepoRebaseTest : GitRebaseBaseTest() {
|
||||
list
|
||||
},
|
||||
plainTextEditor = { it })
|
||||
GitTestingRebaseProcess(project, GitRebaseParams.editCommits("HEAD^", rebaseEditor, false), repo).rebase()
|
||||
GitTestingRebaseProcess(project, GitRebaseParams.editCommits(vcs.version, "HEAD^", rebaseEditor, false), repo).rebase()
|
||||
|
||||
assertNotNull("Didn't get any rebase entries", receivedEntries)
|
||||
assertEquals("Rebase entries parsed incorrectly", listOf(GitRebaseEntry.Action.PICK), receivedEntries!!.map { it.action })
|
||||
@@ -514,7 +514,7 @@ class GitSingleRepoRebaseTest : GitRebaseBaseTest() {
|
||||
}
|
||||
|
||||
private fun rebaseInteractively(revision: String = "master") {
|
||||
GitTestingRebaseProcess(project, GitRebaseParams(null, null, revision, true, false), repo).rebase()
|
||||
GitTestingRebaseProcess(project, GitRebaseParams(vcs.version, null, null, revision, true, false), repo).rebase()
|
||||
}
|
||||
|
||||
fun `test checkout with rebase`() {
|
||||
@@ -539,7 +539,7 @@ class GitSingleRepoRebaseTest : GitRebaseBaseTest() {
|
||||
}
|
||||
|
||||
private fun simpleParams(newBase: String): GitRebaseParams {
|
||||
return GitRebaseParams(newBase)
|
||||
return GitRebaseParams(vcs.version, newBase)
|
||||
}
|
||||
|
||||
internal fun file(path: String) = repo.file(path)
|
||||
|
||||
Reference in New Issue
Block a user