Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git error handling in saveRecipients #32

Merged
merged 1 commit into from
Feb 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion password/recipients.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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