Skip to content

Commit

Permalink
Fix git error handling in saveRecipients
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
dominikschulz committed Feb 11, 2017
1 parent 9057284 commit 0919a2b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion password/recipients.go
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"strings"

"github.com/fatih/color"
"github.com/justwatchcom/gopass/fsutil"
"github.com/justwatchcom/gopass/gpg"
)
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
}

Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion password/store.go
Expand Up @@ -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
Expand Down

0 comments on commit 0919a2b

Please sign in to comment.