From 9f49aaed839ae608a0ffdaa0656b3975d3404002 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sat, 20 Aug 2016 01:29:07 +0200 Subject: storage: support ConfigStorage, memory done, fs wip --- storage/filesystem/internal/dotgit/dotgit.go | 21 ++++++++++++++++++--- storage/filesystem/internal/dotgit/dotgit_test.go | 8 ++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'storage/filesystem') diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go index f365f13..448f6a2 100644 --- a/storage/filesystem/internal/dotgit/dotgit.go +++ b/storage/filesystem/internal/dotgit/dotgit.go @@ -12,17 +12,18 @@ import ( const ( suffix = ".git" packedRefsPath = "packed-refs" + configPath = "config" ) var ( // ErrNotFound is returned by New when the path is not found. ErrNotFound = errors.New("path not found") - // ErrIdxNotFound is returned by Idxfile when the idx file is not found on the - // repository. + // ErrIdxNotFound is returned by Idxfile when the idx file is not found ErrIdxNotFound = errors.New("idx file not found") // ErrPackfileNotFound is returned by Packfile when the packfile is not found - // on the repository. ErrPackfileNotFound = errors.New("packfile not found") + // ErrConfigNotFound is returned by Config when the config is not found + ErrConfigNotFound = errors.New("config file not found") ) // The DotGit type represents a local git repository on disk. This @@ -103,3 +104,17 @@ func (d *DotGit) Idxfile() (fs.FS, string, error) { return nil, "", ErrIdxNotFound } + +// Config returns the path of the config file +func (d *DotGit) Config() (fs.FS, string, error) { + configFile := d.fs.Join(d.path, configPath) + if _, err := d.fs.Stat(configFile); err != nil { + if os.IsNotExist(err) { + return nil, "", ErrNotFound + } + + return nil, "", err + } + + return d.fs, configFile, nil +} diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go index 6125114..7c39c87 100644 --- a/storage/filesystem/internal/dotgit/dotgit_test.go +++ b/storage/filesystem/internal/dotgit/dotgit_test.go @@ -143,6 +143,14 @@ func (s *SuiteDotGit) TestRefsFromHEADFile(c *C) { c.Assert(string(ref.Target()), Equals, "refs/heads/master") } +func (s *SuiteDotGit) TestConfig(c *C) { + _, d := s.newFixtureDir(c, "spinnaker") + fs, path, err := d.Config() + c.Assert(err, IsNil) + c.Assert(fs, NotNil) + c.Assert(path, Not(Equals), "") +} + func findReference(refs []*core.Reference, name string) *core.Reference { n := core.ReferenceName(name) for _, ref := range refs { -- cgit