aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/user_adopt.go48
-rw-r--r--commands/user_create.go4
-rw-r--r--doc/man/git-bug-user-adopt.129
-rw-r--r--doc/man/git-bug-user.12
-rw-r--r--doc/md/git-bug_user_adopt.md22
-rw-r--r--misc/bash_completion/git-bug21
-rw-r--r--misc/zsh_completion/git-bug2
7 files changed, 126 insertions, 2 deletions
diff --git a/commands/user_adopt.go b/commands/user_adopt.go
new file mode 100644
index 00000000..5313e366
--- /dev/null
+++ b/commands/user_adopt.go
@@ -0,0 +1,48 @@
+package commands
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/util/interrupt"
+ "github.com/spf13/cobra"
+)
+
+func runUserAdopt(cmd *cobra.Command, args []string) error {
+ backend, err := cache.NewRepoCache(repo)
+ if err != nil {
+ return err
+ }
+ defer backend.Close()
+ interrupt.RegisterCleaner(backend.Close)
+
+ prefix := args[0]
+
+ i, err := backend.ResolveIdentityPrefix(prefix)
+ if err != nil {
+ return err
+ }
+
+ err = backend.SetUserIdentity(i)
+ if err != nil {
+ return err
+ }
+
+ _, _ = fmt.Fprintf(os.Stderr, "Your identity is now: %s\n", i.DisplayName())
+
+ return nil
+}
+
+var userAdoptCmd = &cobra.Command{
+ Use: "adopt <id>",
+ Short: "Adopt an existing identity as your own.",
+ PreRunE: loadRepo,
+ RunE: runUserAdopt,
+ Args: cobra.ExactArgs(1),
+}
+
+func init() {
+ userCmd.AddCommand(userAdoptCmd)
+ userAdoptCmd.Flags().SortFlags = false
+}
diff --git a/commands/user_create.go b/commands/user_create.go
index 2d007600..00ec5b9b 100644
--- a/commands/user_create.go
+++ b/commands/user_create.go
@@ -18,6 +18,10 @@ func runUserCreate(cmd *cobra.Command, args []string) error {
defer backend.Close()
interrupt.RegisterCleaner(backend.Close)
+ _, _ = fmt.Fprintf(os.Stderr, "Before creating a new identity, please be aware that "+
+ "you can also use an already existing one using \"git bug user adopt\". As an example, "+
+ "you can do that if your identity has already been created by an importer.\n\n")
+
preName, err := backend.GetUserName()
if err != nil {
return err
diff --git a/doc/man/git-bug-user-adopt.1 b/doc/man/git-bug-user-adopt.1
new file mode 100644
index 00000000..f61bc5d4
--- /dev/null
+++ b/doc/man/git-bug-user-adopt.1
@@ -0,0 +1,29 @@
+.TH "GIT-BUG" "1" "Feb 2019" "Generated from git-bug's source code" ""
+.nh
+.ad l
+
+
+.SH NAME
+.PP
+git\-bug\-user\-adopt \- Adopt an existing identity as your own.
+
+
+.SH SYNOPSIS
+.PP
+\fBgit\-bug user adopt <id> [flags]\fP
+
+
+.SH DESCRIPTION
+.PP
+Adopt an existing identity as your own.
+
+
+.SH OPTIONS
+.PP
+\fB\-h\fP, \fB\-\-help\fP[=false]
+ help for adopt
+
+
+.SH SEE ALSO
+.PP
+\fBgit\-bug\-user(1)\fP
diff --git a/doc/man/git-bug-user.1 b/doc/man/git-bug-user.1
index acb9259f..65988c9b 100644
--- a/doc/man/git-bug-user.1
+++ b/doc/man/git-bug-user.1
@@ -26,4 +26,4 @@ Display or change the user identity
.SH SEE ALSO
.PP
-\fBgit\-bug(1)\fP, \fBgit\-bug\-user\-create(1)\fP, \fBgit\-bug\-user\-ls(1)\fP
+\fBgit\-bug(1)\fP, \fBgit\-bug\-user\-adopt(1)\fP, \fBgit\-bug\-user\-create(1)\fP, \fBgit\-bug\-user\-ls(1)\fP
diff --git a/doc/md/git-bug_user_adopt.md b/doc/md/git-bug_user_adopt.md
new file mode 100644
index 00000000..f89cdf68
--- /dev/null
+++ b/doc/md/git-bug_user_adopt.md
@@ -0,0 +1,22 @@
+## git-bug user adopt
+
+Adopt an existing identity as your own.
+
+### Synopsis
+
+Adopt an existing identity as your own.
+
+```
+git-bug user adopt <id> [flags]
+```
+
+### Options
+
+```
+ -h, --help help for adopt
+```
+
+### SEE ALSO
+
+* [git-bug user](git-bug_user.md) - Display or change the user identity.
+
diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug
index 237a0df0..c83d33ae 100644
--- a/misc/bash_completion/git-bug
+++ b/misc/bash_completion/git-bug
@@ -799,6 +799,26 @@ _git-bug_title()
noun_aliases=()
}
+_git-bug_user_adopt()
+{
+ last_command="git-bug_user_adopt"
+
+ command_aliases=()
+
+ commands=()
+
+ flags=()
+ two_word_flags=()
+ local_nonpersistent_flags=()
+ flags_with_completion=()
+ flags_completion=()
+
+
+ must_have_one_flag=()
+ must_have_one_noun=()
+ noun_aliases=()
+}
+
_git-bug_user_create()
{
last_command="git-bug_user_create"
@@ -849,6 +869,7 @@ _git-bug_user()
command_aliases=()
commands=()
+ commands+=("adopt")
commands+=("create")
commands+=("ls")
diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug
index 6fc3cf8e..232cd3c1 100644
--- a/misc/zsh_completion/git-bug
+++ b/misc/zsh_completion/git-bug
@@ -33,7 +33,7 @@ case $state in
_arguments '2: :(edit)'
;;
user)
- _arguments '2: :(create ls)'
+ _arguments '2: :(adopt create ls)'
;;
*)
_arguments '*: :_files'