Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-10-19 13:22:46 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-11-30 15:24:45 +0300
commit60d1b61f3afc26a7f17d9a0c90567ea03addf293 (patch)
treeff8e65a33345c8a850cc068a6f47487a5128fcc8
parent8600e1c08e37c984b5c7354df00e47af1ada09f3 (diff)
config: Refactor `SetGitPath()` to be easier to extend
The `SetGitPath()` function is quite hard to read given that the different cases are intermingled without clear separation from each other. Refactor it to use a switch statement to more clearly show which cases there are and make it readily extensible.
-rw-r--r--internal/gitaly/config/config.go34
1 files changed, 16 insertions, 18 deletions
diff --git a/internal/gitaly/config/config.go b/internal/gitaly/config/config.go
index 8ef965ab4..4b46684e3 100644
--- a/internal/gitaly/config/config.go
+++ b/internal/gitaly/config/config.go
@@ -365,27 +365,25 @@ func SkipHooks() bool {
// SetGitPath populates the variable GitPath with the path to the `git`
// executable. It warns if no path was specified in the configuration.
func (cfg *Cfg) SetGitPath() error {
- if cfg.Git.BinPath != "" {
- return nil
- }
-
- if path, ok := os.LookupEnv("GITALY_TESTING_GIT_BINARY"); ok {
- cfg.Git.BinPath = path
- return nil
- }
-
- resolvedPath, err := exec.LookPath("git")
- if err != nil {
- if errors.Is(err, exec.ErrNotFound) {
- return fmt.Errorf(`"git" executable not found, set path to it in the configuration file or add it to the PATH`)
+ switch {
+ case cfg.Git.BinPath != "":
+ // Nothing to do.
+ case os.Getenv("GITALY_TESTING_GIT_BINARY") != "":
+ cfg.Git.BinPath = os.Getenv("GITALY_TESTING_GIT_BINARY")
+ default:
+ resolvedPath, err := exec.LookPath("git")
+ if err != nil {
+ if errors.Is(err, exec.ErrNotFound) {
+ return fmt.Errorf(`"git" executable not found, set path to it in the configuration file or add it to the PATH`)
+ }
}
- }
- log.WithFields(log.Fields{
- "resolvedPath": resolvedPath,
- }).Warn("git path not configured. Using default path resolution")
+ log.WithFields(log.Fields{
+ "resolvedPath": resolvedPath,
+ }).Warn("git path not configured. Using default path resolution")
- cfg.Git.BinPath = resolvedPath
+ cfg.Git.BinPath = resolvedPath
+ }
return nil
}