diff options
author | Michael Muré <batolettre@gmail.com> | 2020-12-08 15:17:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-08 15:17:22 +0100 |
commit | bf476f98d1656850e2f3fd349adea504007a8313 (patch) | |
tree | 595f3875590c89fe1c5a30e2e732f8aee9b35361 /commands | |
parent | 54d123c6753d053df8400beea316e13690c851f4 (diff) | |
parent | 8128bb79b0db9023a98c356e4e173d846057c577 (diff) | |
download | git-bug-bf476f98d1656850e2f3fd349adea504007a8313.tar.gz |
Merge pull request #510 from MichaelMure/repo-rework
Repo rework
Diffstat (limited to 'commands')
-rw-r--r-- | commands/env.go | 2 | ||||
-rw-r--r-- | commands/ls.go | 5 | ||||
-rw-r--r-- | commands/select/select.go | 22 |
3 files changed, 10 insertions, 19 deletions
diff --git a/commands/env.go b/commands/env.go index 5658342d..8d12c5bf 100644 --- a/commands/env.go +++ b/commands/env.go @@ -54,7 +54,7 @@ func loadRepo(env *Env) func(*cobra.Command, []string) error { return fmt.Errorf("unable to get the current working directory: %q", err) } - env.repo, err = repository.NewGoGitRepo(cwd, []repository.ClockLoader{bug.ClockLoader}) + env.repo, err = repository.OpenGoGitRepo(cwd, []repository.ClockLoader{bug.ClockLoader}) if err == repository.ErrNotARepo { return fmt.Errorf("%s must be run from within a git repo", rootCommandName) } diff --git a/commands/ls.go b/commands/ls.go index f6d654b1..327fd37f 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -110,7 +110,10 @@ func runLs(env *Env, opts lsOptions, args []string) error { return err } - allIds := env.backend.QueryBugs(q) + allIds, err := env.backend.QueryBugs(q) + if err != nil { + return err + } bugExcerpt := make([]*cache.BugExcerpt, len(allIds)) for i, id := range allIds { diff --git a/commands/select/select.go b/commands/select/select.go index cf861fcc..3df74387 100644 --- a/commands/select/select.go +++ b/commands/select/select.go @@ -5,14 +5,12 @@ import ( "io" "io/ioutil" "os" - "path" "github.com/pkg/errors" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" "github.com/MichaelMure/git-bug/entity" - "github.com/MichaelMure/git-bug/repository" ) const selectFile = "select" @@ -71,14 +69,12 @@ func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string // Select will select a bug for future use func Select(repo *cache.RepoCache, id entity.Id) error { - selectPath := selectFilePath(repo) - - f, err := os.OpenFile(selectPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) + f, err := repo.LocalStorage().OpenFile(selectFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { return err } - _, err = f.WriteString(id.String()) + _, err = f.Write([]byte(id.String())) if err != nil { return err } @@ -88,15 +84,11 @@ func Select(repo *cache.RepoCache, id entity.Id) error { // Clear will clear the selected bug, if any func Clear(repo *cache.RepoCache) error { - selectPath := selectFilePath(repo) - - return os.Remove(selectPath) + return repo.LocalStorage().Remove(selectFile) } func selected(repo *cache.RepoCache) (*cache.BugCache, error) { - selectPath := selectFilePath(repo) - - f, err := os.Open(selectPath) + f, err := repo.LocalStorage().Open(selectFile) if err != nil { if os.IsNotExist(err) { return nil, nil @@ -115,7 +107,7 @@ func selected(repo *cache.RepoCache) (*cache.BugCache, error) { id := entity.Id(buf) if err := id.Validate(); err != nil { - err = os.Remove(selectPath) + err = repo.LocalStorage().Remove(selectFile) if err != nil { return nil, errors.Wrap(err, "error while removing invalid select file") } @@ -135,7 +127,3 @@ func selected(repo *cache.RepoCache) (*cache.BugCache, error) { return b, nil } - -func selectFilePath(repo repository.RepoCommon) string { - return path.Join(repo.GetPath(), "git-bug", selectFile) -} |