mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-14 17:51:44 +03:00
Merge pull request #273 from MichaelMure/user-create-set
cmd: "user create" only assign the user identity if not set
This commit is contained in:
commit
ef6801a37f
4
cache/repo_cache.go
vendored
4
cache/repo_cache.go
vendored
@ -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) {
|
||||
|
@ -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())
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user