diff options
Diffstat (limited to 'identity/identity.go')
-rw-r--r-- | identity/identity.go | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/identity/identity.go b/identity/identity.go index c33a8818..b5222a3e 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -227,17 +227,35 @@ func SetUserIdentity(repo repository.RepoConfig, identity *Identity) error { // GetUserIdentity read the current user identity, set with a git config entry func GetUserIdentity(repo repository.Repo) (*Identity, error) { - configs, err := repo.LocalConfig().ReadAll(identityConfigKey) + id, err := GetUserIdentityId(repo) if err != nil { return nil, err } + i, err := ReadLocal(repo, id) + if err == ErrIdentityNotExist { + innerErr := repo.LocalConfig().RemoveAll(identityConfigKey) + if innerErr != nil { + _, _ = fmt.Fprintln(os.Stderr, errors.Wrap(innerErr, "can't clear user identity").Error()) + } + return nil, err + } + + return i, nil +} + +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 { - return nil, ErrNoIdentitySet + return entity.UnsetId, ErrNoIdentitySet } if len(configs) > 1 { - return nil, ErrMultipleIdentitiesSet + return entity.UnsetId, ErrMultipleIdentitiesSet } var id entity.Id @@ -246,19 +264,10 @@ func GetUserIdentity(repo repository.Repo) (*Identity, error) { } if err := id.Validate(); err != nil { - return nil, err - } - - i, err := ReadLocal(repo, id) - if err == ErrIdentityNotExist { - innerErr := repo.LocalConfig().RemoveAll(identityConfigKey) - if innerErr != nil { - _, _ = fmt.Fprintln(os.Stderr, errors.Wrap(innerErr, "can't clear user identity").Error()) - } - return nil, err + return entity.UnsetId, err } - return i, nil + return id, nil } // IsUserIdentitySet say if the user has set his identity |