diff options
-rw-r--r-- | cache/repo_cache.go | 4 | ||||
-rw-r--r-- | commands/user_create.go | 9 | ||||
-rw-r--r-- | identity/identity.go | 10 |
3 files changed, 22 insertions, 1 deletions
diff --git a/cache/repo_cache.go b/cache/repo_cache.go index ec4cf436..90a489c8 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -877,6 +877,10 @@ func (c *RepoCache) GetUserIdentity() (*IdentityCache, error) { return cached, nil } +func (c *RepoCache) IsUserIdentitySet() (bool, error) { + return identity.IsUserIdentitySet(c.repo) +} + // NewIdentity create a new identity // The new identity is written in the repository (commit) func (c *RepoCache) NewIdentity(name string, email string) (*IdentityCache, error) { diff --git a/commands/user_create.go b/commands/user_create.go index 88cc94de..15b9767e 100644 --- a/commands/user_create.go +++ b/commands/user_create.go @@ -53,11 +53,18 @@ func runUserCreate(cmd *cobra.Command, args []string) error { return err } - err = backend.SetUserIdentity(id) + set, err := backend.IsUserIdentitySet() if err != nil { return err } + if !set { + err = backend.SetUserIdentity(id) + if err != nil { + return err + } + } + _, _ = fmt.Fprintln(os.Stderr) fmt.Println(id.Id()) diff --git a/identity/identity.go b/identity/identity.go index ed8e39e0..cd47c1b7 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -261,6 +261,16 @@ func GetUserIdentity(repo repository.Repo) (*Identity, error) { return i, nil } +// IsUserIdentitySet say if the user has set his identity +func IsUserIdentitySet(repo repository.Repo) (bool, error) { + configs, err := repo.LocalConfig().ReadAll(identityConfigKey) + if err != nil { + return false, err + } + + return len(configs) == 1, nil +} + func (i *Identity) AddVersion(version *Version) { i.versions = append(i.versions, version) } |