From f93f5c52d3776a3daf141cbf06a740fcb80d39f6 Mon Sep 17 00:00:00 2001 From: Mihail Buryakov Date: Fri, 31 Oct 2025 16:23:03 +0200 Subject: [PATCH] [eel-vcs] IJPL-204860 eliminate hacky wsl-only fix, add GitExecutable.isRemote (cherry picked from commit 2d57034b2d993da860941cb6ac9001654e5899df) IJ-CR-180951 GitOrigin-RevId: 00198b29345ca30910f4d21bfd05097006c48679 --- .../git4idea/commands/GitScriptGenerator.java | 4 ---- .../commit/signing/GpgAgentConfigurator.kt | 19 ++++++------------- .../src/git4idea/config/GitExecutable.kt | 9 +++++++++ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java b/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java index e45b01a1d18c..2e975e6e25bd 100644 --- a/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java +++ b/plugins/git4idea/src/git4idea/commands/GitScriptGenerator.java @@ -29,10 +29,6 @@ public class GitScriptGenerator extends ScriptGeneratorImpl { } } - public GitScriptGenerator(@Nullable WSLDistribution wslDistribution) { - myWSLDistribution = wslDistribution; - } - @Override protected @NotNull String getJavaExecutablePath() { if (myWSLDistribution != null) { diff --git a/plugins/git4idea/src/git4idea/commit/signing/GpgAgentConfigurator.kt b/plugins/git4idea/src/git4idea/commit/signing/GpgAgentConfigurator.kt index 778847ce2566..4c2a57106660 100644 --- a/plugins/git4idea/src/git4idea/commit/signing/GpgAgentConfigurator.kt +++ b/plugins/git4idea/src/git4idea/commit/signing/GpgAgentConfigurator.kt @@ -25,7 +25,6 @@ import com.intellij.openapi.util.io.NioFiles import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vcs.ProjectLevelVcsManager import com.intellij.openapi.vcs.VcsException -import com.intellij.platform.ide.impl.wsl.WslEelDescriptor import com.intellij.platform.util.coroutines.flow.debounceBatch import com.intellij.util.application import com.intellij.util.concurrency.annotations.RequiresBackgroundThread @@ -55,7 +54,6 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext -import org.intellij.lang.annotations.Language import org.jetbrains.annotations.VisibleForTesting import java.io.IOException import java.nio.file.InvalidPathException @@ -75,14 +73,17 @@ internal class GpgAgentConfigurator(private val project: Project, private val cs @JvmStatic fun isEnabled(project: Project, executable: GitExecutable): Boolean = (Registry.`is`("git.commit.gpg.signing.enable.embedded.pinentry", false) || application.isUnitTestMode) - && (SystemInfo.isUnix || (executable !is GitExecutable.Unknown && !executable.isLocal)) + && (isRemDevOrWsl(executable) || isLocalUnix(executable)) && signingIsEnabledInAnyRepo(project) private fun isUnitTestModeOnUnix(): Boolean = SystemInfo.isUnix && application.isUnitTestMode + private fun isLocalUnix(executable: GitExecutable): Boolean = + executable.isLocal && SystemInfo.isUnix + private fun isRemDevOrWsl(executable: GitExecutable): Boolean = - AppMode.isRemoteDevHost() || (executable !is GitExecutable.Unknown && !executable.isLocal) + AppMode.isRemoteDevHost() || executable.isRemote // do not configure Gpg Agent for roots without commit.gpgSign and user.signingkey enabled private fun signingIsEnabledInAnyRepo(project: Project): Boolean = GitRepositoryManager.getInstance(project) @@ -366,15 +367,7 @@ internal class PinentryShellScriptLauncherGenerator(val executable: GitExecutabl } fun getCommandLine(): String { - val gitScriptGenerator = when (executable) { - is GitExecutable.Eel -> { - GitScriptGenerator((executable.eel.descriptor as? WslEelDescriptor)?.distribution) - } - else -> { - GitScriptGenerator(executable) - } - } - return gitScriptGenerator.addParameters(*getCommandLineParameters()).commandLine(PinentryApp::class.java, false) + return GitScriptGenerator(executable).addParameters(*getCommandLineParameters()).commandLine(PinentryApp::class.java, false) } private fun getScriptTemplate(fallbackPinentryPath: String?): String { diff --git a/plugins/git4idea/src/git4idea/config/GitExecutable.kt b/plugins/git4idea/src/git4idea/config/GitExecutable.kt index 7140ec45b7e2..b461676f0ca2 100644 --- a/plugins/git4idea/src/git4idea/config/GitExecutable.kt +++ b/plugins/git4idea/src/git4idea/config/GitExecutable.kt @@ -71,6 +71,7 @@ sealed class GitExecutable { abstract val id: String abstract val exePath: String abstract val isLocal: Boolean + open val isRemote: Boolean get() = !isLocal /** * Convert an absolute file path into a form that can be passed into executable arguments. @@ -162,6 +163,9 @@ sealed class GitExecutable { override fun getLocaleEnv(): Map = VcsLocaleHelper.getDefaultLocaleEnvironmentVars("git") } + /** + * Ideally, can represent any git executable, either local or remote. Actual instantiation depends on the feature flags enabled. + */ data class Eel(override val exePath: @NonNls String, val eel: EelApi) : GitExecutable() { private val delegate = Local(exePath) @@ -197,6 +201,10 @@ sealed class GitExecutable { } } + /** + * Legacy option of handling wsl git. + * Now [Eel] is used for representing wsl git (as well as git inside docker and any other non-demdev remote git). + */ data class Wsl( override val exePath: String, val distribution: WSLDistribution, @@ -300,6 +308,7 @@ sealed class GitExecutable { data class Unknown(override val id: String, override val exePath: String, val errorMessage: @Nls String) : GitExecutable() { override val isLocal: Boolean = false + override val isRemote: Boolean = false override fun toString(): String = "$id: $exePath" override fun getModificationTime(): Long {