diff options
Diffstat (limited to 'commands/select')
-rw-r--r-- | commands/select/select.go | 15 | ||||
-rw-r--r-- | commands/select/select_test.go | 6 |
2 files changed, 11 insertions, 10 deletions
diff --git a/commands/select/select.go b/commands/select/select.go index b080d277..fdc87154 100644 --- a/commands/select/select.go +++ b/commands/select/select.go @@ -7,11 +7,12 @@ import ( "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" - "github.com/MichaelMure/git-bug/util/git" - "github.com/pkg/errors" ) const selectFile = "select" @@ -69,7 +70,7 @@ func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string } // Select will select a bug for future use -func Select(repo *cache.RepoCache, id string) error { +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) @@ -77,7 +78,7 @@ func Select(repo *cache.RepoCache, id string) error { return err } - _, err = f.WriteString(id) + _, err = f.WriteString(id.String()) if err != nil { return err } @@ -112,8 +113,8 @@ func selected(repo *cache.RepoCache) (*cache.BugCache, error) { return nil, fmt.Errorf("the select file should be < 100 bytes") } - h := git.Hash(buf) - if !h.IsValid() { + id := entity.Id(buf) + if err := id.Validate(); err != nil { err = os.Remove(selectPath) if err != nil { return nil, errors.Wrap(err, "error while removing invalid select file") @@ -122,7 +123,7 @@ func selected(repo *cache.RepoCache) (*cache.BugCache, error) { return nil, fmt.Errorf("select file in invalid, removing it") } - b, err := repo.ResolveBug(string(h)) + b, err := repo.ResolveBug(id) if err != nil { return nil, err } diff --git a/commands/select/select_test.go b/commands/select/select_test.go index 393ec88b..989d6b3c 100644 --- a/commands/select/select_test.go +++ b/commands/select/select_test.go @@ -52,12 +52,12 @@ func TestSelect(t *testing.T) { require.Equal(t, b1.Id(), b3.Id()) // override selection with same id - b4, _, err := ResolveBug(repoCache, []string{b1.Id()}) + b4, _, err := ResolveBug(repoCache, []string{b1.Id().String()}) require.NoError(t, err) require.Equal(t, b1.Id(), b4.Id()) // override selection with a prefix - b5, _, err := ResolveBug(repoCache, []string{b1.HumanId()}) + b5, _, err := ResolveBug(repoCache, []string{b1.Id().Human()}) require.NoError(t, err) require.Equal(t, b1.Id(), b5.Id()) @@ -67,7 +67,7 @@ func TestSelect(t *testing.T) { require.Equal(t, b1.Id(), b6.Id()) // override with a different id - b7, _, err := ResolveBug(repoCache, []string{b2.Id()}) + b7, _, err := ResolveBug(repoCache, []string{b2.Id().String()}) require.NoError(t, err) require.Equal(t, b2.Id(), b7.Id()) |