diff --git a/password/recipients.go b/password/recipients.go index d3797d9ffb..d56430b73f 100644 --- a/password/recipients.go +++ b/password/recipients.go @@ -11,6 +11,7 @@ import ( "sort" "strings" + "github.com/fatih/color" "github.com/justwatchcom/gopass/fsutil" "github.com/justwatchcom/gopass/gpg" ) @@ -133,7 +134,32 @@ func (s *Store) saveRecipients() error { return err } + if err := s.gitAdd(s.idFile()); err != nil { + if err == ErrGitNotInit { + return nil + } + return err + } + if err := s.gitCommit(fmt.Sprintf("Updated recipients")); err != nil { + return err + } + if !s.persistKeys { + // push to remote repo + if s.autoPush { + if err := s.gitPush("", ""); err != nil { + if err == ErrGitNotInit { + return nil + } + if err == ErrGitNoRemote { + msg := "Warning: git has no remote. Ignoring auto-push option\n" + + "Run: gopass git remote add origin ..." + fmt.Println(color.YellowString(msg)) + return nil + } + return err + } + } return nil } @@ -155,7 +181,8 @@ func (s *Store) saveRecipients() error { return err } if err := s.gitCommit(fmt.Sprintf("Exported Public Keys %s", r)); err != nil { - return err + fmt.Println(color.RedString("Failed to git commit: %s", err)) + continue } } @@ -165,6 +192,12 @@ func (s *Store) saveRecipients() error { if err == ErrGitNotInit { return nil } + if err == ErrGitNoRemote { + msg := "Warning: git has not remote. Ignoring auto-push option\n" + + "Run: gopass git remote add origin ..." + fmt.Println(color.YellowString(msg)) + return nil + } return err } } diff --git a/password/store.go b/password/store.go index 1f0b23174b..218671359a 100644 --- a/password/store.go +++ b/password/store.go @@ -294,7 +294,7 @@ func (s *Store) SetConfirm(name string, content []byte, cb RecipientCallback) er if err == ErrGitNoRemote { msg := "Warning: git has not remote. Ignoring auto-push option\n" + "Run: gopass git remote add origin ..." - fmt.Println(color.RedString(msg)) + fmt.Println(color.YellowString(msg)) return nil } return err