From 1845c0bf9c3b77c52484ee4e7f9b15f7eab6edce Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Tue, 9 Aug 2016 14:19:43 -0600 Subject: [PATCH 1/2] config: ensure .gitconfig is loaded before Unmarshal call --- config/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/config.go b/config/config.go index a8750547..43abc5f8 100644 --- a/config/config.go +++ b/config/config.go @@ -131,6 +131,8 @@ func NewFrom(v Values) *Configuration { // Otherwise, the field will be set to the value of calling the // appropriately-typed method on the specified environment. func (c *Configuration) Unmarshal(v interface{}) error { + c.loadGitConfig() + into := reflect.ValueOf(v) if into.Kind() != reflect.Ptr { return fmt.Errorf("lfs/config: unable to parse non-pointer type of %T", v) From 3723cb25707bfb115667bd0f2cfac609be1e6fbd Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Tue, 9 Aug 2016 14:27:11 -0600 Subject: [PATCH 2/2] config: use config.Unmarshal to fill FetchPruneConfig --- config/config.go | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/config/config.go b/config/config.go index 43abc5f8..d0d2eeec 100644 --- a/config/config.go +++ b/config/config.go @@ -28,21 +28,21 @@ var ( type FetchPruneConfig struct { // The number of days prior to current date for which (local) refs other than HEAD // will be fetched with --recent (default 7, 0 = only fetch HEAD) - FetchRecentRefsDays int + FetchRecentRefsDays int `git:"lfs.fetchrecentrefsdays"` // Makes the FetchRecentRefsDays option apply to remote refs from fetch source as well (default true) - FetchRecentRefsIncludeRemotes bool + FetchRecentRefsIncludeRemotes bool `git:"lfs.fetchrecentremoterefs"` // number of days prior to latest commit on a ref that we'll fetch previous // LFS changes too (default 0 = only fetch at ref) - FetchRecentCommitsDays int + FetchRecentCommitsDays int `git:"lfs.fetchrecentcommitsdays"` // Whether to always fetch recent even without --recent - FetchRecentAlways bool + FetchRecentAlways bool `git:"lfs.fetchrecentalways"` // Number of days added to FetchRecent*; data outside combined window will be // deleted when prune is run. (default 3) - PruneOffsetDays int + PruneOffsetDays int `git:"lfs.pruneoffsetdays"` // Always verify with remote before pruning - PruneVerifyRemoteAlways bool + PruneVerifyRemoteAlways bool `git:"lfs.pruneverifyremotealways"` // Name of remote to check for unpushed and verify checks - PruneRemoteName string + PruneRemoteName string `git:"lfs.pruneremotetocheck"` } type Configuration struct { @@ -450,21 +450,18 @@ func (c *Configuration) AllGitConfig() map[string]string { return c.gitConfig } -func (c *Configuration) FetchPruneConfig() (fetchconf FetchPruneConfig) { - fetchconf.FetchRecentRefsDays = c.GitConfigInt("lfs.fetchrecentrefsdays", 7) - fetchconf.FetchRecentRefsIncludeRemotes = c.GitConfigBool("lfs.fetchrecentremoterefs", true) - fetchconf.FetchRecentCommitsDays = c.GitConfigInt("lfs.fetchrecentcommitsdays", 0) - fetchconf.FetchRecentAlways = c.GitConfigBool("lfs.fetchrecentalways", false) - fetchconf.PruneOffsetDays = c.GitConfigInt("lfs.pruneoffsetdays", 3) - fetchconf.PruneVerifyRemoteAlways = c.GitConfigBool("lfs.pruneverifyremotealways", false) - - if v, ok := c.GitConfig("lfs.pruneremotetocheck"); ok { - fetchconf.PruneRemoteName = v - } else { - fetchconf.PruneRemoteName = "origin" +func (c *Configuration) FetchPruneConfig() FetchPruneConfig { + f := &FetchPruneConfig{ + FetchRecentRefsDays: 7, + FetchRecentRefsIncludeRemotes: true, + PruneOffsetDays: 3, + PruneRemoteName: "origin", } - return fetchconf + if err := c.Unmarshal(f); err != nil { + panic(err.Error()) + } + return *f } func (c *Configuration) SkipDownloadErrors() bool {