diff options
author | Michael Muré <batolettre@gmail.com> | 2022-11-19 11:33:12 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2022-11-28 17:20:25 +0100 |
commit | 0ac39a7ab5db077fcf0df827e32bf6e625e980da (patch) | |
tree | e453d6fd244cb322bdc6305c0088aa3c0331b075 /entities | |
parent | c6bb6b9c7ecddb679966b1561e2e909a9ee5e8cd (diff) | |
download | git-bug-0ac39a7ab5db077fcf0df827e32bf6e625e980da.tar.gz |
WIP
Diffstat (limited to 'entities')
-rw-r--r-- | entities/bug/err.go | 17 | ||||
-rw-r--r-- | entities/bug/operation.go | 7 | ||||
-rw-r--r-- | entities/identity/common.go | 3 | ||||
-rw-r--r-- | entities/identity/identity.go | 4 | ||||
-rw-r--r-- | entities/identity/identity_test.go | 7 | ||||
-rw-r--r-- | entities/identity/identity_user.go | 2 |
6 files changed, 8 insertions, 32 deletions
diff --git a/entities/bug/err.go b/entities/bug/err.go deleted file mode 100644 index 1bd174bb..00000000 --- a/entities/bug/err.go +++ /dev/null @@ -1,17 +0,0 @@ -package bug - -import ( - "errors" - - "github.com/MichaelMure/git-bug/entity" -) - -var ErrBugNotExist = errors.New("bug doesn't exist") - -func NewErrMultipleMatchBug(matching []entity.Id) *entity.ErrMultipleMatch { - return entity.NewErrMultipleMatch("bug", matching) -} - -func NewErrMultipleMatchOp(matching []entity.Id) *entity.ErrMultipleMatch { - return entity.NewErrMultipleMatch("operation", matching) -} diff --git a/entities/bug/operation.go b/entities/bug/operation.go index 41d80700..04365046 100644 --- a/entities/bug/operation.go +++ b/entities/bug/operation.go @@ -21,12 +21,7 @@ const ( ) // Operation define the interface to fulfill for an edit operation of a Bug -type Operation interface { - dag.Operation - - // Apply the operation to a Snapshot to create the final state - Apply(snapshot *Snapshot) -} +type Operation = dag.OperationWithApply[*Snapshot] // make sure that package external operations do conform to our interface var _ Operation = &dag.NoOpOperation[*Snapshot]{} diff --git a/entities/identity/common.go b/entities/identity/common.go index 5c6445e9..ba35792c 100644 --- a/entities/identity/common.go +++ b/entities/identity/common.go @@ -2,14 +2,11 @@ package identity import ( "encoding/json" - "errors" "fmt" "github.com/MichaelMure/git-bug/entity" ) -var ErrIdentityNotExist = errors.New("identity doesn't exist") - func NewErrMultipleMatch(matching []entity.Id) *entity.ErrMultipleMatch { return entity.NewErrMultipleMatch("identity", matching) } diff --git a/entities/identity/identity.go b/entities/identity/identity.go index d497dbcc..9bc53aed 100644 --- a/entities/identity/identity.go +++ b/entities/identity/identity.go @@ -109,7 +109,7 @@ func read(repo repository.Repo, ref string) (*Identity, error) { hashes, err := repo.ListCommits(ref) if err != nil { - return nil, ErrIdentityNotExist + return nil, entity.NewErrNotFound("identity") } if len(hashes) == 0 { return nil, fmt.Errorf("empty identity") @@ -202,7 +202,7 @@ func RemoveIdentity(repo repository.ClockedRepo, id entity.Id) error { } if len(fullMatches) == 0 { - return ErrIdentityNotExist + return entity.NewErrNotFound("identity") } for _, ref := range fullMatches { diff --git a/entities/identity/identity_test.go b/entities/identity/identity_test.go index f0c3bbe9..0ecc8058 100644 --- a/entities/identity/identity_test.go +++ b/entities/identity/identity_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/lamport" ) @@ -278,13 +279,13 @@ func TestIdentityRemove(t *testing.T) { require.NoError(t, err) _, err = ReadLocal(repo, rene.Id()) - require.Error(t, ErrIdentityNotExist, err) + require.ErrorAs(t, entity.ErrNotFound{}, err) _, err = ReadRemote(repo, "remoteA", string(rene.Id())) - require.Error(t, ErrIdentityNotExist, err) + require.ErrorAs(t, entity.ErrNotFound{}, err) _, err = ReadRemote(repo, "remoteB", string(rene.Id())) - require.Error(t, ErrIdentityNotExist, err) + require.ErrorAs(t, entity.ErrNotFound{}, err) ids, err := ListLocalIds(repo) require.NoError(t, err) diff --git a/entities/identity/identity_user.go b/entities/identity/identity_user.go index cd67459e..e671e662 100644 --- a/entities/identity/identity_user.go +++ b/entities/identity/identity_user.go @@ -23,7 +23,7 @@ func GetUserIdentity(repo repository.Repo) (*Identity, error) { } i, err := ReadLocal(repo, id) - if err == ErrIdentityNotExist { + if entity.IsErrNotFound(err) { innerErr := repo.LocalConfig().RemoveAll(identityConfigKey) if innerErr != nil { _, _ = fmt.Fprintln(os.Stderr, errors.Wrap(innerErr, "can't clear user identity").Error()) |