diff options
author | amine <hilalyamine@gmail.com> | 2019-10-31 19:05:50 +0100 |
---|---|---|
committer | amine <hilalyamine@gmail.com> | 2019-10-31 19:05:50 +0100 |
commit | 7f177c4750b4acf70cc3fd3d43c19685179e527b (patch) | |
tree | b3a896099d508c679f736ecf32dc70039149fe11 /repository/config_git.go | |
parent | ab935674a26f2eef5d8014c615b9b5bc1f402135 (diff) | |
download | git-bug-7f177c4750b4acf70cc3fd3d43c19685179e527b.tar.gz |
repository: add ReadTimestamp methods and improve naming
Diffstat (limited to 'repository/config_git.go')
-rw-r--r-- | repository/config_git.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/repository/config_git.go b/repository/config_git.go index 81b9b819..80b23cc7 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 |