diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-10 12:41:54 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-10 12:48:24 +0300 |
commit | 96bdc9439798f202647360242cb5109cece5e2d8 (patch) | |
tree | 5b6b098bd4a5480c2b648f15f6370ca6eb5aa4c2 | |
parent | 03a82b12c4f30ff3ffce9ad3332223f104ef7c53 (diff) |
git: Fix warning on startup about Git binary fallbackpks-git-command-factory-fix-warning
Gitaly supports different execution environments with bundled Git and
distributed Git. If no such execution environment was properly set up
though we will fall back to try and resolve Git via PATH as a last
resort. Due to the way our environment constructors are arranged right
now though the fallback will always be constructed, which ultimately
leads to a warning that Git wasn't properly configured even though it in
fact was.
Fix this issue by removing the fallback Git environment from our default
constructors. Instead, we explicitly construct it only in the case where
we didn't find any other available execution environment. Like this, we
can now only print the warning when it actually applies.
Changelog: fixed
-rw-r--r-- | internal/git/command_factory.go | 13 | ||||
-rw-r--r-- | internal/git/execution_environment.go | 5 |
2 files changed, 12 insertions, 6 deletions
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go index 210288dd4..77ff1976c 100644 --- a/internal/git/command_factory.go +++ b/internal/git/command_factory.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/prometheus/client_golang/prometheus" + "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/v15/internal/cgroups" "gitlab.com/gitlab-org/gitaly/v15/internal/command" "gitlab.com/gitlab-org/gitaly/v15/internal/git/alternates" @@ -193,7 +194,17 @@ func setupGitExecutionEnvironments(cfg config.Cfg, factoryCfg execCommandFactory } if len(execEnvs) == 0 { - return nil, nil, fmt.Errorf("could not set up any Git execution environments") + execEnv, err := FallbackGitEnvironmentConstructor{}.Construct(cfg) + if err != nil { + return nil, nil, fmt.Errorf("could not set up any Git execution environments") + } + execEnv.EnvironmentVariables = append(execEnv.EnvironmentVariables, sharedEnvironment...) + + logrus.WithFields(logrus.Fields{ + "resolvedPath": execEnv.BinaryPath, + }).Warn("Git has not been properly configured, falling back to Git found on PATH") + + execEnvs = append(execEnvs, execEnv) } return execEnvs, func() { diff --git a/internal/git/execution_environment.go b/internal/git/execution_environment.go index c35d5e108..99aa795c3 100644 --- a/internal/git/execution_environment.go +++ b/internal/git/execution_environment.go @@ -35,7 +35,6 @@ var ( Suffix: "-v2.35.1.gl1", }, DistributedGitEnvironmentConstructor{}, - FallbackGitEnvironmentConstructor{}, } ) @@ -247,10 +246,6 @@ func (c FallbackGitEnvironmentConstructor) Construct(config.Cfg) (ExecutionEnvir return ExecutionEnvironment{}, fmt.Errorf("resolving git executable: %w", err) } - logrus.WithFields(logrus.Fields{ - "resolvedPath": resolvedPath, - }).Warn("git path not configured. Using default path resolution") - return ExecutionEnvironment{ BinaryPath: resolvedPath, // We always pretend that this environment is disabled. This has the effect that |