From 2f03cadb8499ac0059cb0e7653aaa34060807c0c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 3 Nov 2025 14:01:36 +0100 Subject: [PATCH] IJPL-216405 IJ-MR-181153 Terminal completion for git branches doesn't work GitOrigin-RevId: 9bf99f986a243f837483bdf237344f55de06c7d8 --- .idea/modules.xml | 2 + BUILD.bazel | 2 + build/bazel-generated-file-list.txt | 2 + intellij.idea.community.main.iml | 1 + plugins/git4idea/BUILD.bazel | 5 -- plugins/git4idea/intellij.vcs.git.iml | 2 - plugins/git4idea/localHistory/BUILD.bazel | 16 +++++ .../intellij.vcs.git.localHistory.iml | 11 +++ .../intellij.vcs.git.localHistory.xml | 0 plugins/git4idea/plugin-content.yaml | 6 ++ .../git4idea/resources/META-INF/plugin.xml | 4 +- plugins/git4idea/terminal/BUILD.bazel | 69 +++++++++++++++++++ .../terminal/intellij.vcs.git.terminal.iml | 30 ++++++++ .../resources/intellij.vcs.git.terminal.xml | 2 +- .../vcs/git}/terminal/GitAliasContributor.kt | 4 +- .../git}/terminal/GitCommandSpecsProvider.kt | 6 +- .../terminal/GitShellCommandOverrideSpec.kt | 7 +- .../vcs/git}/terminal/GitTerminalBundle.kt | 6 +- .../git}/terminal/GitAliasContributorTest.kt | 3 +- .../GitShellCommandOverrideSpecTest.kt | 7 +- 20 files changed, 159 insertions(+), 26 deletions(-) create mode 100644 plugins/git4idea/localHistory/BUILD.bazel create mode 100644 plugins/git4idea/localHistory/intellij.vcs.git.localHistory.iml rename plugins/git4idea/{ => localHistory}/resources/intellij.vcs.git.localHistory.xml (100%) create mode 100644 plugins/git4idea/terminal/BUILD.bazel create mode 100644 plugins/git4idea/terminal/intellij.vcs.git.terminal.iml rename plugins/git4idea/{ => terminal}/resources/intellij.vcs.git.terminal.xml (66%) rename plugins/git4idea/{src/git4idea => terminal/src/com/intellij/vcs/git}/terminal/GitAliasContributor.kt (94%) rename plugins/git4idea/{src/git4idea => terminal/src/com/intellij/vcs/git}/terminal/GitCommandSpecsProvider.kt (74%) rename plugins/git4idea/{src/git4idea => terminal/src/com/intellij/vcs/git}/terminal/GitShellCommandOverrideSpec.kt (98%) rename plugins/git4idea/{src/git4idea => terminal/src/com/intellij/vcs/git}/terminal/GitTerminalBundle.kt (70%) rename plugins/git4idea/{tests/git4idea => terminal/testSrc/com/intellij/vcs/git}/terminal/GitAliasContributorTest.kt (91%) rename plugins/git4idea/{tests/git4idea => terminal/testSrc/com/intellij/vcs/git}/terminal/GitShellCommandOverrideSpecTest.kt (97%) diff --git a/.idea/modules.xml b/.idea/modules.xml index ae99f6772ff5..5e9704f40949 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -1528,8 +1528,10 @@ + + diff --git a/BUILD.bazel b/BUILD.bazel index 4ad2ebee1c52..be2685ec69ca 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -560,6 +560,8 @@ jvm_library( "//tools/intellij.tools.ide.starter.junit5:ide-starter-junit5", "//tools/intellij.tools.ide.starter.junit5:ide-starter-junit5_test_lib", "//plugins/terminal/tests:tests_test_lib", + "//plugins/git4idea/terminal", + "//plugins/git4idea/terminal:terminal_test_lib", ] ) ### auto-generated section `build intellij.idea.community.main` end diff --git a/build/bazel-generated-file-list.txt b/build/bazel-generated-file-list.txt index 3872ca8a23bc..edde11b8f6fa 100644 --- a/build/bazel-generated-file-list.txt +++ b/build/bazel-generated-file-list.txt @@ -928,8 +928,10 @@ plugins/git-modal-commit plugins/git4idea plugins/git4idea/frontend plugins/git4idea/intellij.vcs.git.coverage +plugins/git4idea/localHistory plugins/git4idea/rt plugins/git4idea/shared +plugins/git4idea/terminal plugins/github/github-core plugins/github/github-git plugins/github/github-json diff --git a/intellij.idea.community.main.iml b/intellij.idea.community.main.iml index 3082d240fb11..49d549b0aedb 100644 --- a/intellij.idea.community.main.iml +++ b/intellij.idea.community.main.iml @@ -257,5 +257,6 @@ + \ No newline at end of file diff --git a/plugins/git4idea/BUILD.bazel b/plugins/git4idea/BUILD.bazel index 3a663c330bfb..f3558c5b5817 100644 --- a/plugins/git4idea/BUILD.bazel +++ b/plugins/git4idea/BUILD.bazel @@ -97,8 +97,6 @@ jvm_library( "//plugins/performanceTesting/core:performanceTesting", "//platform/backend/observation", "//platform/util/coroutines", - "//plugins/terminal", - "//plugins/terminal/completion", "//libraries/http-client", "//platform/platform-impl/ui", "//platform/dvcs-impl/shared", @@ -212,9 +210,6 @@ jvm_library( "//platform/backend/observation", "//platform/backend/observation:observation_test_lib", "//platform/util/coroutines", - "//plugins/terminal", - "//plugins/terminal/completion", - "//plugins/terminal/completion:completion_test_lib", "//libraries/http-client", "//platform/platform-impl/ui", "//platform/dvcs-impl/shared", diff --git a/plugins/git4idea/intellij.vcs.git.iml b/plugins/git4idea/intellij.vcs.git.iml index a12fd6c2aeee..36fa38f6aedf 100644 --- a/plugins/git4idea/intellij.vcs.git.iml +++ b/plugins/git4idea/intellij.vcs.git.iml @@ -113,8 +113,6 @@ - - diff --git a/plugins/git4idea/localHistory/BUILD.bazel b/plugins/git4idea/localHistory/BUILD.bazel new file mode 100644 index 000000000000..d970f3dc0ab9 --- /dev/null +++ b/plugins/git4idea/localHistory/BUILD.bazel @@ -0,0 +1,16 @@ +### auto-generated section `build intellij.vcs.git.localHistory` start +load("@rules_jvm//:jvm.bzl", "jvm_library", "resourcegroup") + +resourcegroup( + name = "localHistory_resources", + srcs = glob(["resources/**/*"]), + strip_prefix = "resources" +) + +jvm_library( + name = "localHistory", + visibility = ["//visibility:public"], + srcs = glob([], allow_empty = True), + resources = [":localHistory_resources"] +) +### auto-generated section `build intellij.vcs.git.localHistory` end \ No newline at end of file diff --git a/plugins/git4idea/localHistory/intellij.vcs.git.localHistory.iml b/plugins/git4idea/localHistory/intellij.vcs.git.localHistory.iml new file mode 100644 index 000000000000..510e3ffb6679 --- /dev/null +++ b/plugins/git4idea/localHistory/intellij.vcs.git.localHistory.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/git4idea/resources/intellij.vcs.git.localHistory.xml b/plugins/git4idea/localHistory/resources/intellij.vcs.git.localHistory.xml similarity index 100% rename from plugins/git4idea/resources/intellij.vcs.git.localHistory.xml rename to plugins/git4idea/localHistory/resources/intellij.vcs.git.localHistory.xml diff --git a/plugins/git4idea/plugin-content.yaml b/plugins/git4idea/plugin-content.yaml index e26a39c7fa85..f9a79a324589 100644 --- a/plugins/git4idea/plugin-content.yaml +++ b/plugins/git4idea/plugin-content.yaml @@ -7,6 +7,12 @@ - name: lib/modules/intellij.vcs.git.frontend.jar contentModules: - name: intellij.vcs.git.frontend +- name: lib/modules/intellij.vcs.git.localHistory.jar + contentModules: + - name: intellij.vcs.git.localHistory +- name: lib/modules/intellij.vcs.git.terminal.jar + contentModules: + - name: intellij.vcs.git.terminal - name: lib/vcs-git-frontend.jar contentModules: - name: intellij.vcs.git.shared diff --git a/plugins/git4idea/resources/META-INF/plugin.xml b/plugins/git4idea/resources/META-INF/plugin.xml index 2eec236ea8d4..3df8efeec353 100644 --- a/plugins/git4idea/resources/META-INF/plugin.xml +++ b/plugins/git4idea/resources/META-INF/plugin.xml @@ -20,8 +20,8 @@ - - + + diff --git a/plugins/git4idea/terminal/BUILD.bazel b/plugins/git4idea/terminal/BUILD.bazel new file mode 100644 index 000000000000..6a46905d5aea --- /dev/null +++ b/plugins/git4idea/terminal/BUILD.bazel @@ -0,0 +1,69 @@ +### auto-generated section `build intellij.vcs.git.terminal` start +load("@rules_jvm//:jvm.bzl", "jvm_library", "resourcegroup") + +resourcegroup( + name = "terminal_resources", + srcs = glob(["resources/**/*"]), + strip_prefix = "resources" +) + +jvm_library( + name = "terminal", + module_name = "intellij.vcs.git.terminal", + visibility = ["//visibility:public"], + srcs = glob(["src/**/*.kt", "src/**/*.java", "src/**/*.form"], allow_empty = True), + resources = [":terminal_resources"], + deps = [ + "//platform/ide-core", + "//platform/util", + "//platform/util:util-ui", + "//plugins/git4idea/shared", + "//plugins/terminal", + "//plugins/git4idea:vcs-git", + "//plugins/terminal/completion", + "//platform/core-api:core", + "//platform/dvcs-impl:vcs-dvcs-impl", + "@lib//:kotlin-stdlib", + "@lib//:jetbrains-annotations", + ] +) + +jvm_library( + name = "terminal_test_lib", + visibility = ["//visibility:public"], + srcs = glob(["testSrc/**/*.kt", "testSrc/**/*.java", "testSrc/**/*.form"], allow_empty = True), + associates = [":terminal"], + deps = [ + "//platform/ide-core", + "//platform/util", + "//platform/util:util-ui", + "//plugins/git4idea/shared", + "//plugins/terminal", + "//plugins/git4idea:vcs-git", + "//plugins/git4idea:vcs-git_test_lib", + "//plugins/terminal/completion", + "//plugins/terminal/completion:completion_test_lib", + "//platform/core-api:core", + "//platform/dvcs-impl:vcs-dvcs-impl", + "//platform/dvcs-impl:vcs-dvcs-impl_test_lib", + "@lib//:kotlin-stdlib", + "@lib//:jetbrains-annotations", + "@lib//:junit5", + "//platform/testFramework", + "//platform/testFramework:testFramework_test_lib", + "//platform/vcs-impl/shared", + "//platform/vcs-api/shared", + "@lib//:assert_j", + "//libraries/mockito", + ] +) +### auto-generated section `build intellij.vcs.git.terminal` end + +### auto-generated section `test intellij.vcs.git.terminal` start +load("@community//build:tests-options.bzl", "jps_test") + +jps_test( + name = "terminal_test", + runtime_deps = [":terminal_test_lib"] +) +### auto-generated section `test intellij.vcs.git.terminal` end \ No newline at end of file diff --git a/plugins/git4idea/terminal/intellij.vcs.git.terminal.iml b/plugins/git4idea/terminal/intellij.vcs.git.terminal.iml new file mode 100644 index 000000000000..e6726e7ccc7c --- /dev/null +++ b/plugins/git4idea/terminal/intellij.vcs.git.terminal.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/git4idea/resources/intellij.vcs.git.terminal.xml b/plugins/git4idea/terminal/resources/intellij.vcs.git.terminal.xml similarity index 66% rename from plugins/git4idea/resources/intellij.vcs.git.terminal.xml rename to plugins/git4idea/terminal/resources/intellij.vcs.git.terminal.xml index 42ab406df20c..1751be6fafc4 100644 --- a/plugins/git4idea/resources/intellij.vcs.git.terminal.xml +++ b/plugins/git4idea/terminal/resources/intellij.vcs.git.terminal.xml @@ -4,6 +4,6 @@ - + \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/terminal/GitAliasContributor.kt b/plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitAliasContributor.kt similarity index 94% rename from plugins/git4idea/src/git4idea/terminal/GitAliasContributor.kt rename to plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitAliasContributor.kt index 23c79473f166..517d44b4d149 100644 --- a/plugins/git4idea/src/git4idea/terminal/GitAliasContributor.kt +++ b/plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitAliasContributor.kt @@ -1,5 +1,5 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package git4idea.terminal +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.vcs.git.terminal import com.intellij.terminal.completion.spec.ShellAliasSuggestion import com.intellij.terminal.completion.spec.ShellRuntimeDataGenerator diff --git a/plugins/git4idea/src/git4idea/terminal/GitCommandSpecsProvider.kt b/plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitCommandSpecsProvider.kt similarity index 74% rename from plugins/git4idea/src/git4idea/terminal/GitCommandSpecsProvider.kt rename to plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitCommandSpecsProvider.kt index 5365cf7aa6fe..9018234bc0ec 100644 --- a/plugins/git4idea/src/git4idea/terminal/GitCommandSpecsProvider.kt +++ b/plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitCommandSpecsProvider.kt @@ -1,11 +1,11 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package git4idea.terminal +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.vcs.git.terminal import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecConflictStrategy import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecInfo import org.jetbrains.plugins.terminal.block.completion.spec.ShellCommandSpecsProvider -internal class GitCommandSpecsProvider : ShellCommandSpecsProvider { +private class GitCommandSpecsProvider : ShellCommandSpecsProvider { override fun getCommandSpecs(): List = listOf( ShellCommandSpecInfo.create(gitOverrideSpec, ShellCommandSpecConflictStrategy.OVERRIDE) ) diff --git a/plugins/git4idea/src/git4idea/terminal/GitShellCommandOverrideSpec.kt b/plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitShellCommandOverrideSpec.kt similarity index 98% rename from plugins/git4idea/src/git4idea/terminal/GitShellCommandOverrideSpec.kt rename to plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitShellCommandOverrideSpec.kt index f4f1573f5832..8a4965bdaf6d 100644 --- a/plugins/git4idea/src/git4idea/terminal/GitShellCommandOverrideSpec.kt +++ b/plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitShellCommandOverrideSpec.kt @@ -1,5 +1,5 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package git4idea.terminal +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.vcs.git.terminal import com.intellij.icons.AllIcons import com.intellij.openapi.vcs.LocalFilePath @@ -22,8 +22,7 @@ internal const val GET_LOCAL_BRANCHES_COMMAND = "$GET_ALL_BRANCHES_COMMAND \"ref internal const val GET_REMOTE_BRANCHES_COMMAND = "$GET_ALL_BRANCHES_COMMAND \"refs/remotes/**\"" internal val ShellRuntimeContext.repository: GitRepository? - get() = GitUtil.getRepositoryManager(project) - .getRepositoryForFileQuick(LocalFilePath(currentDirectory, true)) + get() = GitUtil.getRepositoryManager(project).getRepositoryForFileQuick(LocalFilePath(currentDirectory, true)) // Find remote generators in the git.json file by searching for scripts doing: // remote -v diff --git a/plugins/git4idea/src/git4idea/terminal/GitTerminalBundle.kt b/plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitTerminalBundle.kt similarity index 70% rename from plugins/git4idea/src/git4idea/terminal/GitTerminalBundle.kt rename to plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitTerminalBundle.kt index a545c03fa426..a5233aebdf09 100644 --- a/plugins/git4idea/src/git4idea/terminal/GitTerminalBundle.kt +++ b/plugins/git4idea/terminal/src/com/intellij/vcs/git/terminal/GitTerminalBundle.kt @@ -1,12 +1,12 @@ -// 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.terminal +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.vcs.git.terminal import com.intellij.DynamicBundle import org.jetbrains.annotations.Nls import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.PropertyKey -object GitTerminalBundle { +internal object GitTerminalBundle { @NonNls const val BUNDLE: String = "messages.GitTerminalBundle" private val INSTANCE = DynamicBundle(GitTerminalBundle::class.java, BUNDLE) diff --git a/plugins/git4idea/tests/git4idea/terminal/GitAliasContributorTest.kt b/plugins/git4idea/terminal/testSrc/com/intellij/vcs/git/terminal/GitAliasContributorTest.kt similarity index 91% rename from plugins/git4idea/tests/git4idea/terminal/GitAliasContributorTest.kt rename to plugins/git4idea/terminal/testSrc/com/intellij/vcs/git/terminal/GitAliasContributorTest.kt index aa5b9eb2137e..73c3a11f0a7e 100644 --- a/plugins/git4idea/tests/git4idea/terminal/GitAliasContributorTest.kt +++ b/plugins/git4idea/terminal/testSrc/com/intellij/vcs/git/terminal/GitAliasContributorTest.kt @@ -1,6 +1,7 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package git4idea.terminal +import com.intellij.vcs.git.terminal.parseGitAlias import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test diff --git a/plugins/git4idea/tests/git4idea/terminal/GitShellCommandOverrideSpecTest.kt b/plugins/git4idea/terminal/testSrc/com/intellij/vcs/git/terminal/GitShellCommandOverrideSpecTest.kt similarity index 97% rename from plugins/git4idea/tests/git4idea/terminal/GitShellCommandOverrideSpecTest.kt rename to plugins/git4idea/terminal/testSrc/com/intellij/vcs/git/terminal/GitShellCommandOverrideSpecTest.kt index 4a56fe006abc..66556b0f7db4 100644 --- a/plugins/git4idea/tests/git4idea/terminal/GitShellCommandOverrideSpecTest.kt +++ b/plugins/git4idea/terminal/testSrc/com/intellij/vcs/git/terminal/GitShellCommandOverrideSpecTest.kt @@ -1,10 +1,11 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package git4idea.terminal import com.intellij.openapi.vcs.FilePath import com.intellij.terminal.completion.spec.ShellCommandResult import com.intellij.testFramework.fixtures.BasePlatformTestCase import com.intellij.testFramework.replaceService +import com.intellij.vcs.git.terminal.* import com.intellij.vcs.log.Hash import com.intellij.vcs.log.impl.HashImpl import git4idea.GitBranch @@ -241,8 +242,8 @@ class GitShellCommandOverrideSpecTest : BasePlatformTestCase() { private fun GitBranch.toCommandResult(currentBranch: GitLocalBranch): String = when (this) { - is GitRemoteBranch -> "remotes/${name}$COLUMN_SPLIT_CHARACTER" - is GitLocalBranch -> "heads/${name}$COLUMN_SPLIT_CHARACTER" + if (this == currentBranch) "*" else "" + is GitRemoteBranch -> "remotes/${name}${COLUMN_SPLIT_CHARACTER}" + is GitLocalBranch -> "heads/${name}${COLUMN_SPLIT_CHARACTER}" + if (this == currentBranch) "*" else "" else -> error("unknown branch type: $this") }