diff --git a/internal/action/config.go b/internal/action/config.go index ecf6eff6fa..33ebbb94f9 100644 --- a/internal/action/config.go +++ b/internal/action/config.go @@ -2,14 +2,12 @@ package action import ( "context" - "errors" "fmt" "github.com/gopasspw/gopass/internal/action/exit" "github.com/gopasspw/gopass/internal/config" "github.com/gopasspw/gopass/internal/out" "github.com/gopasspw/gopass/internal/set" - istore "github.com/gopasspw/gopass/internal/store" "github.com/gopasspw/gopass/pkg/ctxutil" "github.com/gopasspw/gopass/pkg/debug" "github.com/urfave/cli/v2" @@ -109,23 +107,15 @@ func (s *Action) setConfigValue(ctx context.Context, store, key, value string) e return fmt.Errorf("local config file %s didn't exist in store, this is unexpected", configFile) } - switch err := st.Add(ctx, configFile); { - case err == nil: - debug.Log("Added local config for commit") - case errors.Is(err, istore.ErrGitNotInit): - debug.Log("Skipping staging of local config %q: %v", configFile, err) - default: + if err := st.TryAdd(ctx, configFile); err != nil { return fmt.Errorf("failed to Add local config %q: %w", configFile, err) } + debug.Log("Added local config for commit") - switch err := st.Commit(ctx, "Update config"); { - case err == nil: - debug.Log("Committed local config") - case errors.Is(err, istore.ErrGitNotInit), errors.Is(err, istore.ErrGitNothingToCommit): - debug.Log("Skipping Commit of local config: %v", err) - default: + if err := st.TryCommit(ctx, "Update config"); err != nil { return fmt.Errorf("failed to commit local config: %w", err) } + debug.Log("Committed local config") s.printConfigValues(ctx, store, key) diff --git a/internal/action/sync.go b/internal/action/sync.go index 909a1d440b..2757a973e0 100644 --- a/internal/action/sync.go +++ b/internal/action/sync.go @@ -184,9 +184,8 @@ func (s *Action) syncMount(ctx context.Context, mp string) error { } out.Printf(ctxno, "\n "+color.GreenString("%s pull and push ... ", sub.Storage().Name())) - err = sub.Storage().Push(ctx, "", "") - switch { + switch err := sub.Storage().Push(ctx, "", ""); { case err == nil: debug.Log("Push succeeded") out.Printf(ctxno, color.GreenString("OK")) diff --git a/internal/backend/rcs.go b/internal/backend/rcs.go index 310c726d18..cb326c488c 100644 --- a/internal/backend/rcs.go +++ b/internal/backend/rcs.go @@ -15,6 +15,10 @@ type rcs interface { Push(ctx context.Context, remote, location string) error Pull(ctx context.Context, remote, location string) error + TryAdd(ctx context.Context, args ...string) error + TryCommit(ctx context.Context, msg string) error + TryPush(ctx context.Context, remote, location string) error + InitConfig(ctx context.Context, name, email string) error AddRemote(ctx context.Context, remote, location string) error RemoveRemote(ctx context.Context, remote string) error diff --git a/internal/backend/storage/fossilfs/fossil.go b/internal/backend/storage/fossilfs/fossil.go index e1fb489f51..91f9021442 100644 --- a/internal/backend/storage/fossilfs/fossil.go +++ b/internal/backend/storage/fossilfs/fossil.go @@ -3,6 +3,7 @@ package fossilfs import ( "bytes" "context" + "errors" "fmt" "os/exec" "path/filepath" @@ -207,6 +208,21 @@ func (f *Fossil) Add(ctx context.Context, files ...string) error { return f.Cmd(ctx, "fossilAdd", args...) } +// TryAdd adds the listed files to the fossil index. +func (f *Fossil) TryAdd(ctx context.Context, files ...string) error { + err := f.Add(ctx, files...) + if err == nil { + return nil + } + if errors.Is(err, store.ErrGitNotInit) { + debug.Log("Fossil not initialized. Ignoring.") + + return nil + } + + return err +} + // HasStagedChanges returns true if there are any staged changes which can be committed. func (f *Fossil) HasStagedChanges(ctx context.Context) bool { s, err := f.getStatus(ctx) @@ -251,6 +267,26 @@ func (f *Fossil) Commit(ctx context.Context, msg string) error { ) } +// TryCommit calls commit and returns nil if there was nothing to commit or if the Fossil repo was not initialized. +func (f *Fossil) TryCommit(ctx context.Context, msg string) error { + err := f.Commit(ctx, msg) + if err == nil { + return nil + } + if errors.Is(err, store.ErrGitNothingToCommit) { + debug.Log("Nothing to commit. Ignoring.") + + return nil + } + if errors.Is(err, store.ErrGitNotInit) { + debug.Log("Fossil not initialized. Ignoring.") + + return nil + } + + return err +} + // PushPull pushes the repo to it's origin. // optional arguments: remote and branch. func (f *Fossil) PushPull(ctx context.Context, op, remote, branch string) error { @@ -293,6 +329,27 @@ func (f *Fossil) Push(ctx context.Context, remote, branch string) error { return f.PushPull(ctx, "push", remote, branch) } +// TryPush calls Push and returns nil if the Fossil repo was not initialized. +func (f *Fossil) TryPush(ctx context.Context, remote, branch string) error { + err := f.Push(ctx, remote, branch) + if err == nil { + return nil + } + + switch { + case errors.Is(err, store.ErrGitNotInit): + debug.Log("Fossil not initialized. Ignoring.") + + return nil + case errors.Is(err, store.ErrGitNoRemote): + debug.Log("Fossil has no remote. Ignoring.") + + return nil + default: + return err + } +} + // Pull pulls from the fossil remote. func (f *Fossil) Pull(ctx context.Context, remote, branch string) error { if ctxutil.IsNoNetwork(ctx) { diff --git a/internal/backend/storage/fs/rcs.go b/internal/backend/storage/fs/rcs.go index 39baf5c11f..169a1c04f0 100644 --- a/internal/backend/storage/fs/rcs.go +++ b/internal/backend/storage/fs/rcs.go @@ -13,16 +13,31 @@ func (s *Store) Add(ctx context.Context, args ...string) error { return store.ErrGitNotInit } +// TryAdd does nothing. +func (s *Store) TryAdd(ctx context.Context, args ...string) error { + return nil +} + // Commit does nothing. func (s *Store) Commit(ctx context.Context, msg string) error { return store.ErrGitNotInit } +// TryCommit does nothing. +func (s *Store) TryCommit(ctx context.Context, msg string) error { + return nil +} + // Push does nothing. func (s *Store) Push(ctx context.Context, origin, branch string) error { return store.ErrGitNotInit } +// TryPush does nothing. +func (s *Store) TryPush(ctx context.Context, origin, branch string) error { + return nil +} + // Pull does nothing. func (s *Store) Pull(ctx context.Context, origin, branch string) error { return store.ErrGitNotInit diff --git a/internal/backend/storage/gitfs/git.go b/internal/backend/storage/gitfs/git.go index 1ee08ba5b1..a170112845 100644 --- a/internal/backend/storage/gitfs/git.go +++ b/internal/backend/storage/gitfs/git.go @@ -4,6 +4,7 @@ package gitfs import ( "bytes" "context" + "errors" "fmt" "os/exec" "path/filepath" @@ -233,6 +234,21 @@ func (g *Git) Add(ctx context.Context, files ...string) error { return g.Cmd(ctx, "gitAdd", args...) } +// TryAdd calls Add and returns nil if the git repo was not initialized. +func (g *Git) TryAdd(ctx context.Context, files ...string) error { + err := g.Add(ctx, files...) + if err == nil { + return nil + } + if errors.Is(err, store.ErrGitNotInit) { + debug.Log("Git not initialized. Ignoring.") + + return nil + } + + return err +} + // HasStagedChanges returns true if there are any staged changes which can be committed. func (g *Git) HasStagedChanges(ctx context.Context) bool { if err := g.Cmd(ctx, "gitDiffIndex", "diff-index", "--quiet", "HEAD"); err != nil { @@ -272,6 +288,26 @@ func (g *Git) Commit(ctx context.Context, msg string) error { return g.Cmd(ctx, "gitCommit", "commit", fmt.Sprintf("--date=%d +00:00", ctxutil.GetCommitTimestamp(ctx).UTC().Unix()), "-m", msg) } +// TryCommit calls commit and returns nil if there was nothing to commit or if the git repo was not initialized. +func (g *Git) TryCommit(ctx context.Context, msg string) error { + err := g.Commit(ctx, msg) + if err == nil { + return nil + } + if errors.Is(err, store.ErrGitNothingToCommit) { + debug.Log("Nothing to commit. Ignoring.") + + return nil + } + if errors.Is(err, store.ErrGitNotInit) { + debug.Log("Git not initialized. Ignoring.") + + return nil + } + + return err +} + func (g *Git) defaultRemote(ctx context.Context, branch string) string { opts, err := g.ConfigList(ctx) if err != nil { @@ -350,6 +386,27 @@ func (g *Git) PushPull(ctx context.Context, op, remote, branch string) error { return g.Cmd(ctx, "gitPush", "push", remote, branch) } +// TryPush calls Push and returns nil if the git repo was not initialized. +func (g *Git) TryPush(ctx context.Context, remote, branch string) error { + err := g.Push(ctx, remote, branch) + if err == nil { + return nil + } + + switch { + case errors.Is(err, store.ErrGitNotInit): + debug.Log("Git not initialized. Ignoring.") + + return nil + case errors.Is(err, store.ErrGitNoRemote): + debug.Log("Git has no remote. Ignoring.") + + return nil + default: + return err + } +} + // Push pushes to the git remote. func (g *Git) Push(ctx context.Context, remote, branch string) error { if ctxutil.IsNoNetwork(ctx) { diff --git a/internal/create/templates.go b/internal/create/templates.go index 2b33b382b9..92014e97ea 100644 --- a/internal/create/templates.go +++ b/internal/create/templates.go @@ -63,8 +63,8 @@ attributes: type storageSetter interface { Set(context.Context, string, []byte) error - Add(context.Context, ...string) error - Commit(context.Context, string) error + TryAdd(context.Context, ...string) error + TryCommit(context.Context, string) error } func (w *Wizard) writeTemplates(ctx context.Context, s storageSetter) error { @@ -86,14 +86,14 @@ func (w *Wizard) writeTemplates(ctx context.Context, s storageSetter) error { return fmt.Errorf("failed to write default template %s: %w", path, err) } - if err := s.Add(ctx, path); err != nil && !errors.Is(err, store.ErrGitNotInit) { + if err := s.TryAdd(ctx, path); err != nil { return fmt.Errorf("failed to stage changes %s: %w", path, err) } debug.Log("wrote default template to %s", path) } - if err := s.Commit(ctx, "Added default wizard templates"); err != nil && !errors.Is(err, store.ErrGitNotInit) { + if err := s.TryCommit(ctx, "Added default wizard templates"); err != nil { return fmt.Errorf("failed to commit changes: %w", err) } diff --git a/internal/create/wizard_test.go b/internal/create/wizard_test.go index 136dc1bd62..1fa8d3cda8 100644 --- a/internal/create/wizard_test.go +++ b/internal/create/wizard_test.go @@ -19,10 +19,18 @@ func (f *fakeSetter) Add(ctx context.Context, args ...string) error { return nil } +func (f *fakeSetter) TryAdd(ctx context.Context, args ...string) error { + return nil +} + func (f *fakeSetter) Commit(ctx context.Context, msg string) error { return nil } +func (f *fakeSetter) TryCommit(ctx context.Context, msg string) error { + return nil +} + func TestWrite(t *testing.T) { t.Parallel() diff --git a/internal/store/leaf/fsck.go b/internal/store/leaf/fsck.go index 240b23c0cd..6321b6ff0a 100644 --- a/internal/store/leaf/fsck.go +++ b/internal/store/leaf/fsck.go @@ -206,15 +206,8 @@ func (s *Store) fsckLoop(ctx context.Context, path string) error { out.Warningf(ctx, "Nothing to commit: all secrets up to date") } - if err := s.storage.Commit(ctx, ctxutil.GetCommitMessageFull(ctx)); err != nil { - switch { - case errors.Is(err, store.ErrGitNotInit): - out.Warning(ctx, "Cannot commit: git not initialized\nplease run `gopass git init` (and note that manual intervention might be needed)") - case errors.Is(err, store.ErrGitNothingToCommit): - debug.Log("commitAndPush - skipping git commit - nothing to commit") - default: - return fmt.Errorf("failed to commit changes to git: %w", err) - } + if err := s.storage.TryCommit(ctx, ctxutil.GetCommitMessageFull(ctx)); err != nil { + return fmt.Errorf("failed to commit changes to git: %w", err) } return nil diff --git a/internal/store/leaf/move.go b/internal/store/leaf/move.go index be33711ad8..c6f1f913ae 100644 --- a/internal/store/leaf/move.go +++ b/internal/store/leaf/move.go @@ -109,11 +109,7 @@ func (s *Store) directMove(ctx context.Context, from, to string, del bool) error return nil } - if err := s.storage.Add(ctx, pFrom, pTo); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - return nil - } - + if err := s.storage.TryAdd(ctx, pFrom, pTo); err != nil { return fmt.Errorf("failed to add %q and %q to git: %w", pFrom, pTo, err) } @@ -164,15 +160,8 @@ func (s *Store) delete(ctx context.Context, name string, recurse bool) error { return nil } - if err := s.storage.Commit(ctx, fmt.Sprintf("Remove %s from store.", name)); err != nil { - switch { - case errors.Is(err, store.ErrGitNotInit): - debug.Log("skipping git commit - git not initialized") - case errors.Is(err, store.ErrGitNothingToCommit): - debug.Log("skipping git commit - nothing to commit") - default: - return fmt.Errorf("failed to commit changes to git: %w", err) - } + if err := s.storage.TryCommit(ctx, fmt.Sprintf("Remove %s from store.", name)); err != nil { + return fmt.Errorf("failed to commit changes to git: %w", err) } if !config.Bool(ctx, "core.autopush") { @@ -181,11 +170,7 @@ func (s *Store) delete(ctx context.Context, name string, recurse bool) error { return nil } - if err := s.storage.Push(ctx, "", ""); err != nil { - if errors.Is(err, store.ErrGitNotInit) || errors.Is(err, store.ErrGitNoRemote) { - return nil - } - + if err := s.storage.TryPush(ctx, "", ""); err != nil { return fmt.Errorf("failed to push change to git remote: %w", err) } @@ -206,11 +191,7 @@ func (s *Store) deleteRecurse(ctx context.Context, name, path string) error { return err } - if err := s.storage.Add(ctx, name); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - return nil - } - + if err := s.storage.TryAdd(ctx, name); err != nil { return fmt.Errorf("failed to add %q to git: %w", path, err) } debug.Log("pruned") @@ -228,11 +209,7 @@ func (s *Store) deleteSingle(ctx context.Context, path string) error { return err } - if err := s.storage.Add(ctx, path); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - return nil - } - + if err := s.storage.TryAdd(ctx, path); err != nil { return fmt.Errorf("failed to add %q to git: %w", path, err) } diff --git a/internal/store/leaf/recipients.go b/internal/store/leaf/recipients.go index 3efccc2c17..480840c566 100644 --- a/internal/store/leaf/recipients.go +++ b/internal/store/leaf/recipients.go @@ -340,17 +340,10 @@ func (s *Store) UpdateExportedPublicKeys(ctx context.Context, rs []string) (bool } if exported && ctxutil.IsGitCommit(ctx) { - if err := s.storage.Commit(ctx, "Updated exported Public Keys"); err != nil { - switch { - case errors.Is(err, store.ErrGitNothingToCommit): - debug.Log("nothing to commit: %s", err) - case errors.Is(err, store.ErrGitNotInit): - debug.Log("git not initialized: %s", err) - default: - failed = true - - out.Errorf(ctx, "Failed to git commit: %s", err) - } + if err := s.storage.TryCommit(ctx, "Updated exported Public Keys"); err != nil { + failed = true + + out.Errorf(ctx, "Failed to git commit: %s", err) } } @@ -381,11 +374,7 @@ func (s *Store) addMissingKeys(ctx context.Context, exp keyExporter, recipients } // at least one key has been exported exported = true - if err := s.storage.Add(ctx, path); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - continue - } - + if err := s.storage.TryAdd(ctx, path); err != nil { failed = true out.Errorf(ctx, "failed to add public key for %q to git: %s", r, err) @@ -486,16 +475,12 @@ func (s *Store) saveRecipients(ctx context.Context, rs recipientMarshaler, msg s return nil } - if err := s.storage.Add(ctx, idf); err != nil { - if !errors.Is(err, store.ErrGitNotInit) { - return fmt.Errorf("failed to add file %q to git: %w", idf, err) - } + if err := s.storage.TryAdd(ctx, idf); err != nil { + return fmt.Errorf("failed to add file %q to git: %w", idf, err) } - if err := s.storage.Commit(ctx, msg); err != nil { - if !errors.Is(err, store.ErrGitNotInit) && !errors.Is(err, store.ErrGitNothingToCommit) { - return fmt.Errorf("failed to commit changes to git: %w", err) - } + if err := s.storage.TryCommit(ctx, msg); err != nil { + return fmt.Errorf("failed to commit changes to git: %w", err) } if !cfg.GetBoolM(s.alias, "core.autopush") { diff --git a/internal/store/leaf/reencrypt.go b/internal/store/leaf/reencrypt.go index 2f9ec11b6f..bbb45dff0c 100644 --- a/internal/store/leaf/reencrypt.go +++ b/internal/store/leaf/reencrypt.go @@ -100,13 +100,7 @@ func (s *Store) reencrypt(ctx context.Context) error { if conc > 1 { for _, name := range entries { p := s.Passfile(name) - if err := s.storage.Add(ctx, p); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - debug.Log("skipping git add - git not initialized") - - continue - } - + if err := s.storage.TryAdd(ctx, p); err != nil { return fmt.Errorf("failed to add %q to git: %w", p, err) } @@ -114,15 +108,8 @@ func (s *Store) reencrypt(ctx context.Context) error { } } - if err := s.storage.Commit(ctx, ctxutil.GetCommitMessage(ctx)); err != nil { - switch { - case errors.Is(err, store.ErrGitNotInit): - debug.Log("skipping git commit - git not initialized") - case errors.Is(err, store.ErrGitNothingToCommit): - debug.Log("skipping git commit - nothing to commit") - default: - return fmt.Errorf("failed to commit changes to git: %w", err) - } + if err := s.storage.TryCommit(ctx, ctxutil.GetCommitMessage(ctx)); err != nil { + return fmt.Errorf("failed to commit changes to git: %w", err) } return s.reencryptGitPush(ctx) @@ -136,23 +123,7 @@ func (s *Store) reencryptGitPush(ctx context.Context) error { return nil } - if err := s.storage.Push(ctx, "", ""); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - msg := "Warning: git is not initialized for this.storage. Ignoring auto-push option\n" + - "Run: gopass git init" - debug.Log(msg) - - return nil - } - - if errors.Is(err, store.ErrGitNoRemote) { - msg := "Warning: git has no remote. Ignoring auto-push option\n" + - "Run: gopass git remote add origin ..." - debug.Log(msg) - - return nil - } - + if err := s.storage.TryPush(ctx, "", ""); err != nil { return fmt.Errorf("failed to push change to git remote: %w", err) } diff --git a/internal/store/leaf/templates.go b/internal/store/leaf/templates.go index ea6825040d..2df76ac6a3 100644 --- a/internal/store/leaf/templates.go +++ b/internal/store/leaf/templates.go @@ -123,11 +123,7 @@ func (s *Store) SetTemplate(ctx context.Context, name string, content []byte) er return fmt.Errorf("failed to write template: %w", err) } - if err := s.storage.Add(ctx, p); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - return nil - } - + if err := s.storage.TryAdd(ctx, p); err != nil { return fmt.Errorf("failed to add %q to git: %w", p, err) } diff --git a/internal/store/leaf/write.go b/internal/store/leaf/write.go index d4ee18054b..ba2702a3eb 100644 --- a/internal/store/leaf/write.go +++ b/internal/store/leaf/write.go @@ -2,12 +2,10 @@ package leaf import ( "context" - "errors" "fmt" "strings" "github.com/gopasspw/gopass/internal/config" - "github.com/gopasspw/gopass/internal/out" "github.com/gopasspw/gopass/internal/queue" "github.com/gopasspw/gopass/internal/store" "github.com/gopasspw/gopass/pkg/ctxutil" @@ -55,11 +53,7 @@ func (s *Store) Set(ctx context.Context, name string, sec gopass.Byter) error { return nil } - if err := s.storage.Add(ctx, p); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - return nil - } - + if err := s.storage.TryAdd(ctx, p); err != nil { return fmt.Errorf("failed to add %q to git: %w", p, err) } @@ -79,15 +73,8 @@ func (s *Store) Set(ctx context.Context, name string, sec gopass.Byter) error { } func (s *Store) gitCommitAndPush(ctx context.Context, name string) error { - if err := s.storage.Commit(ctx, fmt.Sprintf("Save secret to %s: %s", name, ctxutil.GetCommitMessage(ctx))); err != nil { - switch { - case errors.Is(err, store.ErrGitNotInit): - debug.Log("commitAndPush - skipping git commit - git not initialized") - case errors.Is(err, store.ErrGitNothingToCommit): - debug.Log("commitAndPush - skipping git commit - nothing to commit") - default: - return fmt.Errorf("failed to commit changes to git: %w", err) - } + if err := s.storage.TryCommit(ctx, fmt.Sprintf("Save secret to %s: %s", name, ctxutil.GetCommitMessage(ctx))); err != nil { + return fmt.Errorf("failed to commit changes to git: %w", err) } ctx = config.WithMount(ctx, s.alias) @@ -99,23 +86,7 @@ func (s *Store) gitCommitAndPush(ctx context.Context, name string) error { debug.Log("pushing to remote ...") - if err := s.storage.Push(ctx, "", ""); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - msg := "Warning: git is not initialized for this.storage. Ignoring auto-push option\n" + - "Run: gopass git init" - out.Errorf(ctx, msg) - - return nil - } - - if errors.Is(err, store.ErrGitNoRemote) { - msg := "Warning: git has no remote. Ignoring auto-push option\n" + - "Run: gopass git remote add origin ..." - debug.Log(msg) - - return nil - } - + if err := s.storage.TryPush(ctx, "", ""); err != nil { return fmt.Errorf("failed to push to git remote: %w", err) } diff --git a/internal/store/mockstore/inmem/store.go b/internal/store/mockstore/inmem/store.go index 7e0b757765..b16765ecfc 100644 --- a/internal/store/mockstore/inmem/store.go +++ b/internal/store/mockstore/inmem/store.go @@ -152,16 +152,31 @@ func (m *InMem) Add(ctx context.Context, args ...string) error { return nil } +// TryAdd does nothing. +func (m *InMem) TryAdd(ctx context.Context, args ...string) error { + return nil +} + // Commit does nothing. func (m *InMem) Commit(ctx context.Context, msg string) error { return nil } +// TryCommit does nothing. +func (m *InMem) TryCommit(ctx context.Context, msg string) error { + return nil +} + // Push does nothing. func (m *InMem) Push(ctx context.Context, origin, branch string) error { return nil } +// TryPush does nothing. +func (m *InMem) TryPush(ctx context.Context, origin, branch string) error { + return nil +} + // Pull does nothing. func (m *InMem) Pull(ctx context.Context, origin, branch string) error { return nil diff --git a/internal/store/root/move.go b/internal/store/root/move.go index eca47f8bca..2e462edcfe 100644 --- a/internal/store/root/move.go +++ b/internal/store/root/move.go @@ -46,47 +46,17 @@ func (r *Store) move(ctx context.Context, from, to string, del bool) error { return err } - if err := subFrom.Storage().Commit(ctx, fmt.Sprintf("Move from %s to %s", from, to)); del && err != nil { - switch { - case errors.Is(err, store.ErrGitNotInit): - debug.Log("skipping git commit - git not initialized in %s", subFrom.Alias()) - case errors.Is(err, store.ErrGitNothingToCommit): - debug.Log("skipping git commit - nothing to commit in %s", subFrom.Alias()) - default: - return fmt.Errorf("failed to commit changes to git (%s): %w", subFrom.Alias(), err) - } + if err := subFrom.Storage().TryCommit(ctx, fmt.Sprintf("Move from %s to %s", from, to)); del && err != nil { + return fmt.Errorf("failed to commit changes to git (%s): %w", subFrom.Alias(), err) } if !subFrom.Equals(subTo) { - if err := subTo.Storage().Commit(ctx, fmt.Sprintf("Move from %s to %s", from, to)); err != nil { - switch { - case errors.Is(err, store.ErrGitNotInit): - debug.Log("skipping git commit - git not initialized in %s", subTo.Alias()) - case errors.Is(err, store.ErrGitNothingToCommit): - debug.Log("skipping git commit - nothing to commit in %s", subTo.Alias()) - default: - return fmt.Errorf("failed to commit changes to git (%s): %w", subTo.Alias(), err) - } + if err := subTo.Storage().TryCommit(ctx, fmt.Sprintf("Move from %s to %s", from, to)); err != nil { + return fmt.Errorf("failed to commit changes to git (%s): %w", subTo.Alias(), err) } } - if err := subFrom.Storage().Push(ctx, "", ""); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - msg := "Warning: git is not initialized for this storage. Ignoring auto-push option\n" + - "Run: gopass git init" - debug.Log(msg) - - return nil - } - - if errors.Is(err, store.ErrGitNoRemote) { - msg := "Warning: git has no remote. Ignoring auto-push option\n" + - "Run: gopass git remote add origin ..." - debug.Log(msg) - - return nil - } - + if err := subFrom.Storage().TryPush(ctx, "", ""); err != nil { return fmt.Errorf("failed to push change to git remote: %w", err) } @@ -94,23 +64,7 @@ func (r *Store) move(ctx context.Context, from, to string, del bool) error { return nil } - if err := subTo.Storage().Push(ctx, "", ""); err != nil { - if errors.Is(err, store.ErrGitNotInit) { - msg := "Warning: git is not initialized for this storage. Ignoring auto-push option\n" + - "Run: gopass git init" - debug.Log(msg) - - return nil - } - - if errors.Is(err, store.ErrGitNoRemote) { - msg := "Warning: git has no remote. Ignoring auto-push option\n" + - "Run: gopass git remote add origin ..." - debug.Log(msg) - - return nil - } - + if err := subTo.Storage().TryPush(ctx, "", ""); err != nil { return fmt.Errorf("failed to push change to git remote: %w", err) }