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-09-13 12:54:07 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-09-14 09:24:56 +0300
commitf444b0f3f0a83cf3b018a76041fcc8682abde37f (patch)
treeeea22f4e28066f82fc07f9f537e2f7fd354aa9a6
parent45ae12a10be5f2a69515414f06b37da7d95e579c (diff)
git: Split out parsing of versions from a command
We're about to introduce retrieval of the current Git version via the `git.RepositoryExecutor` interface, which requires the same parsing logic as implemented by `CurrentVersion()`. Let's split out the code to make it easily shareable across both implementations as a preparatory step.
-rw-r--r--internal/git/version.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/internal/git/version.go b/internal/git/version.go
index 33467dfc7..ce5587ada 100644
--- a/internal/git/version.go
+++ b/internal/git/version.go
@@ -6,6 +6,8 @@ import (
"io/ioutil"
"strconv"
"strings"
+
+ "gitlab.com/gitlab-org/gitaly/v14/internal/command"
)
// minimumVersion is the minimum required Git version. If updating this version, be sure to
@@ -43,20 +45,24 @@ func CurrentVersion(ctx context.Context, gitCmdFactory CommandFactory) (Version,
Name: "version",
})
if err != nil {
- return Version{}, err
+ return Version{}, fmt.Errorf("spawning version command: %w", err)
}
+ return parseVersionFromCommand(cmd)
+}
+
+func parseVersionFromCommand(cmd *command.Command) (Version, error) {
versionOutput, err := ioutil.ReadAll(cmd)
if err != nil {
return Version{}, fmt.Errorf("reading version output: %w", err)
}
- if err = cmd.Wait(); err != nil {
- return Version{}, err
+ if err := cmd.Wait(); err != nil {
+ return Version{}, fmt.Errorf("waiting for version command: %w", err)
}
- out := strings.Trim(string(versionOutput), " \n")
- versionString := strings.SplitN(out, " ", 3)
+ trimmedVersionOutput := strings.Trim(string(versionOutput), " \n")
+ versionString := strings.SplitN(trimmedVersionOutput, " ", 3)
if len(versionString) != 3 {
return Version{}, fmt.Errorf("invalid version format: %q", string(versionOutput))
}