diff options
Diffstat (limited to 'identity')
-rw-r--r-- | identity/identity_actions.go | 3 | ||||
-rw-r--r-- | identity/identity_user.go | 27 |
2 files changed, 14 insertions, 16 deletions
diff --git a/identity/identity_actions.go b/identity/identity_actions.go index aa6a2a91..e33b75f9 100644 --- a/identity/identity_actions.go +++ b/identity/identity_actions.go @@ -4,9 +4,10 @@ import ( "fmt" "strings" + "github.com/pkg/errors" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" - "github.com/pkg/errors" ) // Fetch retrieve updates from a remote diff --git a/identity/identity_user.go b/identity/identity_user.go index 60622c12..cd67459e 100644 --- a/identity/identity_user.go +++ b/identity/identity_user.go @@ -35,24 +35,19 @@ func GetUserIdentity(repo repository.Repo) (*Identity, error) { } func GetUserIdentityId(repo repository.Repo) (entity.Id, error) { - configs, err := repo.LocalConfig().ReadAll(identityConfigKey) - if err != nil { - return entity.UnsetId, err - } - - if len(configs) == 0 { + val, err := repo.LocalConfig().ReadString(identityConfigKey) + if err == repository.ErrNoConfigEntry { return entity.UnsetId, ErrNoIdentitySet } - - if len(configs) > 1 { + if err == repository.ErrMultipleConfigEntry { return entity.UnsetId, ErrMultipleIdentitiesSet } - - var id entity.Id - for _, val := range configs { - id = entity.Id(val) + if err != nil { + return entity.UnsetId, err } + var id = entity.Id(val) + if err := id.Validate(); err != nil { return entity.UnsetId, err } @@ -62,10 +57,12 @@ func GetUserIdentityId(repo repository.Repo) (entity.Id, error) { // IsUserIdentitySet say if the user has set his identity func IsUserIdentitySet(repo repository.Repo) (bool, error) { - configs, err := repo.LocalConfig().ReadAll(identityConfigKey) + _, err := repo.LocalConfig().ReadString(identityConfigKey) + if err == repository.ErrNoConfigEntry { + return false, nil + } if err != nil { return false, err } - - return len(configs) == 1, nil + return true, nil } |