Skip to content

Commit 1a0ecb4

Browse files
fix: honor core.autopush during root-store move operations (gopasspw#3535)
* Initial plan * fix: honor core.autopush in root move push path Co-authored-by: dominikschulz <1449175+dominikschulz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dominikschulz <1449175+dominikschulz@users.noreply.github.com>
1 parent 402c780 commit 1a0ecb4

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

‎internal/store/root/move.go‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path"
88
"strings"
99

10+
"github.com/gopasspw/gopass/internal/config"
1011
"github.com/gopasspw/gopass/internal/out"
1112
"github.com/gopasspw/gopass/internal/store"
1213
"github.com/gopasspw/gopass/internal/store/leaf"
@@ -58,16 +59,24 @@ func (r *Store) move(ctx context.Context, from, to string, del bool) error {
5859
}
5960
}
6061

61-
if err := subFrom.Storage().TryPush(ctx, "", ""); err != nil {
62-
return fmt.Errorf("failed to push change to git remote: %w", err)
62+
if config.AsBool(r.cfg.GetM(subFrom.Alias(), "core.autopush")) {
63+
if err := subFrom.Storage().TryPush(ctx, "", ""); err != nil {
64+
return fmt.Errorf("failed to push change to git remote: %w", err)
65+
}
66+
} else {
67+
debug.Log("not pushing %q to git remote, core.autopush is false", subFrom.Alias())
6368
}
6469

6570
if subFrom.Equals(subTo) {
6671
return nil
6772
}
6873

69-
if err := subTo.Storage().TryPush(ctx, "", ""); err != nil {
70-
return fmt.Errorf("failed to push change to git remote: %w", err)
74+
if config.AsBool(r.cfg.GetM(subTo.Alias(), "core.autopush")) {
75+
if err := subTo.Storage().TryPush(ctx, "", ""); err != nil {
76+
return fmt.Errorf("failed to push change to git remote: %w", err)
77+
}
78+
} else {
79+
debug.Log("not pushing %q to git remote, core.autopush is false", subTo.Alias())
7180
}
7281

7382
return nil

‎internal/store/root/move_test.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package root
22

33
import (
4+
"path/filepath"
45
"testing"
56

7+
"github.com/gopasspw/gopass/internal/backend"
68
"github.com/gopasspw/gopass/internal/config"
79
"github.com/gopasspw/gopass/internal/tree"
810
"github.com/gopasspw/gopass/pkg/ctxutil"
@@ -571,6 +573,7 @@ func TestCrossStoreMoveDirectory(t *testing.T) {
571573
"folder/b",
572574
"folder/c",
573575
}
576+
574577
require.NoError(t, u.InitStore(""))
575578

576579
ctx := t.Context()
@@ -602,3 +605,25 @@ func TestCrossStoreMoveDirectory(t *testing.T) {
602605
_, err = rs.Get(ctx, "folder/c")
603606
require.Error(t, err)
604607
}
608+
609+
func TestMoveHonorsAutoPushConfig(t *testing.T) {
610+
u := gptest.NewUnitTester(t)
611+
612+
ctx := config.NewContextInMemory()
613+
ctx = ctxutil.WithAlwaysYes(ctx, true)
614+
ctx = ctxutil.WithHidden(ctx, true)
615+
ctx = backend.WithStorageBackend(ctx, backend.GitFS)
616+
617+
rs, err := createRootStore(ctx, u)
618+
require.NoError(t, err)
619+
620+
require.NoError(t, rs.cfg.Set("", "core.autopush", "false"))
621+
require.NoError(t, rs.cfg.Set("", "core.autosync", "false"))
622+
ctx = rs.WithStoreConfig(ctx)
623+
624+
require.NoError(t, rs.RCSInit(ctx, "", "gopass-tests", "tests@gopass.pw"))
625+
require.NoError(t, rs.RCSAddRemote(ctx, "", "origin", filepath.Join(u.Dir, "missing-remote.git")))
626+
627+
ctx = ctxutil.WithCommitMessage(ctx, "Move foo to bar")
628+
require.NoError(t, rs.Move(ctx, "foo", "bar"))
629+
}

0 commit comments

Comments
 (0)
⌂ 换网址