From 7f177c4750b4acf70cc3fd3d43c19685179e527b Mon Sep 17 00:00:00 2001 From: amine Date: Thu, 31 Oct 2019 19:05:50 +0100 Subject: repository: add ReadTimestamp methods and improve naming --- repository/config_git.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'repository/config_git.go') diff --git a/repository/config_git.go b/repository/config_git.go index 81b9b8195..80b23cc70 100644 --- a/repository/config_git.go +++ b/repository/config_git.go @@ -4,17 +4,20 @@ import ( "fmt" "strconv" "strings" + "time" "github.com/blang/semver" "github.com/pkg/errors" ) +var _ Config = &gitConfig{} + type gitConfig struct { version *semver.Version execFn func(args ...string) (string, error) } -func NewGitConfig(repo *GitRepo, global bool) *gitConfig { +func newGitConfig(repo *GitRepo, global bool) *gitConfig { version, _ := repo.GitVersion() if global { @@ -29,7 +32,7 @@ func NewGitConfig(repo *GitRepo, global bool) *gitConfig { return &gitConfig{ execFn: func(args ...string) (string, error) { - args = append([]string{"config"}, args...) + args = append([]string{"config", "--local"}, args...) return repo.runGitCommand(args...) }, version: version, @@ -111,6 +114,20 @@ func (gc *gitConfig) ReadBool(key string) (bool, error) { return strconv.ParseBool(val) } +func (gc *gitConfig) ReadTimestamp(key string) (*time.Time, error) { + value, err := gc.ReadString(key) + if err != nil { + return nil, err + } + timestamp, err := strconv.Atoi(value) + if err != nil { + return nil, err + } + + t := time.Unix(int64(timestamp), 0) + return &t, nil +} + func (gc *gitConfig) rmSection(keyPrefix string) error { _, err := gc.execFn("--remove-section", keyPrefix) return err -- cgit v1.2.3