[git] IJPL-173721 Detect git executable in WSL v1

WSL v1 is still not supported. However, there is a notification suggesting a hack.
Previously, no notification was shown and git was detected on a host machine producing
"detected dubious ownership" errors.
Also introduced `UnsupportedWSLVersionException` preventing potential miss-leading
notifications in `WindowsExecutableProblemHandler` and hide VCS widget for the
unsupported WSL case.


(cherry picked from commit 9f86bd101b0d2612e116933d2ef086c4b7ae8148)

IJ-MR-151925

GitOrigin-RevId: 5ae4e5711900c7c14f1688f26b245b0f6ddb380f
This commit is contained in:
Ilia Shulgin
2024-12-17 21:20:48 +01:00
committed by intellij-monorepo-bot
parent 0809096b0f
commit da00fd4e04
8 changed files with 37 additions and 15 deletions

View File

@@ -539,7 +539,8 @@ git.executable.new.version.update.available=Update to Git {0}
git.executable.validation.error.start.title=Cannot Run Git
git.executable.validation.error.version.title=Unsupported Git Version {0}
git.executable.validation.error.version.message=At least {0} is required
git.executable.validation.error.wsl1.unsupported.message=WSL version 1 is not supported, see <a href='https://youtrack.jetbrains.com/issue/IDEA-242469'>IDEA-242469</a>
git.executable.validation.error.wsl.start.title=Cannot Run Git in WSL
git.executable.validation.error.wsl1.unsupported.message=WSL version 1 is not supported, see <a href='https://youtrack.jetbrains.com/issue/IDEA-242469'>IDEA-242469</a> for the possible solution.
git.executable.validation.error.xcode.title=Accept XCode/iOS License to Run Git
git.executable.validation.error.xcode.message=Run \u201Csudo xcodebuild -license\u201D and retry (admin rights required)
git.executable.validation.cant.identify.executable.message=Cannot identify version of Git executable {0}

View File

@@ -132,9 +132,8 @@ public abstract class GitImplBase implements Git {
try {
version = GitExecutableManager.getInstance().identifyVersion(executable);
if (version.getType() == GitVersion.Type.WSL1 &&
!Registry.is("git.allow.wsl1.executables")) {
throw new GitNotInstalledException(GitBundle.message("executable.error.git.not.installed"), null);
if (GitVersion.isUnsupportedWslVersion(version.getType())) {
throw new UnsupportedWSLVersionException();
}
}
catch (ProcessCanceledException e) {

View File

@@ -329,8 +329,6 @@ public class GitExecutableDetector {
}
private static @Nullable String checkWslDistribution(@NotNull WSLDistribution distribution) {
if (distribution.getVersion() != 2) return null;
Path root = distribution.getUNCRootPath();
for (String p : UNIX_PATHS) {
Path f = root.resolve(p).resolve(UNIX_EXECUTABLE);

View File

@@ -82,8 +82,14 @@ interface ErrorNotifier {
}
internal fun showUnsupportedVersionError(project: Project, version: GitVersion, errorNotifier: ErrorNotifier) {
val description = if (version.type == GitVersion.Type.WSL1) unsupportedWslVersionDescription() else unsupportedVersionDescription()
errorNotifier.showError(unsupportedVersionMessage(version), description, getLinkToConfigure(project))
if (GitVersion.isUnsupportedWslVersion(version.type)) {
errorNotifier.showError(GitBundle.message("git.executable.validation.error.wsl.start.title"),
GitBundle.message("git.executable.validation.error.wsl1.unsupported.message"),
getLinkToConfigure(project))
}
else {
errorNotifier.showError(unsupportedVersionMessage(version), unsupportedVersionDescription(), getLinkToConfigure(project))
}
}
internal fun unsupportedVersionMessage(version: GitVersion): @Nls String =
@@ -92,9 +98,6 @@ internal fun unsupportedVersionMessage(version: GitVersion): @Nls String =
internal fun unsupportedVersionDescription(): @Nls String =
GitBundle.message("git.executable.validation.error.version.message", GitVersion.MIN.presentation)
internal fun unsupportedWslVersionDescription(): @Nls String =
GitBundle.message("git.executable.validation.error.wsl1.unsupported.message")
internal fun getLinkToConfigure(project: Project): ErrorNotifier.FixOption = ErrorNotifier.FixOption.Configure(project)
internal fun ProcessOutput.dumpToString() = "output: ${stdout}, error output: ${stderr}"

View File

@@ -16,6 +16,7 @@ import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import git4idea.i18n.GitBundle;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -194,14 +195,17 @@ public final class GitVersion implements Comparable<GitVersion> {
return parse(result.getStdout());
}
@ApiStatus.Internal
public static boolean isUnsupportedWslVersion(@NotNull Type type) {
return !Registry.is("git.allow.wsl1.executables") && type == Type.WSL1;
}
/**
* @return true if the version is supported by the plugin
*/
public boolean isSupported() {
Type type = getType();
return type != Type.NULL &&
(Registry.is("git.allow.wsl1.executables") || type != Type.WSL1) &&
compareTo(MIN) >= 0;
return type != Type.NULL && !isUnsupportedWslVersion(type) && compareTo(MIN) >= 0;
}
/**

View File

@@ -0,0 +1,9 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package git4idea.config
import git4idea.i18n.GitBundle
class UnsupportedWSLVersionException : GitVersionIdentificationException(
GitBundle.message("git.executable.validation.error.wsl.start.title"),
null
)

View File

@@ -24,6 +24,8 @@ internal class WindowsExecutableProblemHandler(val project: Project) : GitExecut
}
override fun showError(exception: Throwable, errorNotifier: ErrorNotifier, onErrorResolved: () -> Unit) {
if (exception is UnsupportedWSLVersionException) return
errorNotifier.showError(GitBundle.message("executable.error.git.not.installed"), getHumanReadableErrorFor(exception),
ErrorNotifier.FixOption.Standard(GitBundle.message("install.download.and.install.action")) {
downloadAndInstall(errorNotifier, onErrorResolved)

View File

@@ -24,7 +24,9 @@ import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
import git4idea.GitVcs
import git4idea.branch.GitBranchSyncStatus
import git4idea.branch.GitBranchUtil
import git4idea.config.GitExecutableManager
import git4idea.config.GitVcsSettings
import git4idea.config.GitVersion
import git4idea.i18n.GitBundle
import git4idea.repo.GitRepository
import git4idea.ui.branch.GitCurrentBranchPresenter
@@ -107,6 +109,7 @@ internal class GitToolbarWidgetAction : ExpandableComboAction(), DumbAware {
when (state) {
GitWidgetState.NotActivated,
GitWidgetState.NotSupported,
GitWidgetState.OtherVcs -> {
e.presentation.isEnabledAndVisible = false
return
@@ -176,7 +179,9 @@ internal class GitToolbarWidgetAction : ExpandableComboAction(), DumbAware {
val gitRepository = GitBranchUtil.guessWidgetRepository(project, dataContext)
if (gitRepository != null) {
return GitWidgetState.Repo(gitRepository)
val gitVersion = GitExecutableManager.getInstance().getVersion(project)
return if (GitVersion.isUnsupportedWslVersion(gitVersion.type)) GitWidgetState.NotSupported
else GitWidgetState.Repo(gitRepository)
}
val allVcss = vcsManager.allActiveVcss
@@ -190,6 +195,7 @@ internal class GitToolbarWidgetAction : ExpandableComboAction(), DumbAware {
internal sealed class GitWidgetState {
object NotActivated : GitWidgetState()
object NotSupported : GitWidgetState()
object NoVcs : GitWidgetState()
object OtherVcs : GitWidgetState()
object GitVcs : GitWidgetState()