fix(embeddeddolt): tolerate nothing-to-commit in Commit/CommitWithConfig
bd bootstrap always builds an EmbeddedDoltStore (no ServerMode), and on a
pristine store calls SetConfig followed by CommitWithConfig with an
otherwise-clean working set. EmbeddedDoltStore.Commit wrapped ANY
DOLT_COMMIT error — including Dolt's benign "nothing to commit" — as a
hard failure, so bootstrap died even though the server store (DoltStore)
has always tolerated the identical case via isDoltNothingToCommit. Commit
now checks issueops.IsNothingToCommitError and returns nil for it;
CommitWithConfig inherits the fix since it aliases Commit (GH#3886).
CommitPending relied on Commit's error to decide whether it actually
committed anything ((bool, error) return), so making Commit tolerant would
have made CommitPending report "committed" on every clean-store call.
Switched it to compare HEAD before/after the Commit call instead, which is
correct regardless of how Commit reports a no-op.
CommitMergeResolution deliberately does NOT inherit the new tolerance: a
merge resolution that leaves the working set clean is the --ours case,
where resolving the conflict dirtied nothing but the merge must still be
concluded (see DoltStore.concludeOpenMerge / wy-36ilm F12, and
versioncontrolops.GetMergeBlockers's doc comment, which already flags this
exact gap for embedded). Silently swallowing the error here without also
concluding the merge would leave dolt_merge_status.is_merging true while
reporting success — worse than today's explicit failure. Whether embedded
DOLT_COMMIT('-Am') already concludes an open merge on a clean working set
was not established, so it keeps its own non-tolerant body rather than
guessing; that investigation is left for a follow-up scoped to merge
conclusion semantics.
Added the GH#3886 regression test (TestEmbeddedCommitToleratesNothingToCommit)
covering both Commit and CommitWithConfig on a clean working set.
Agent-Signature: claude-fable-5-high on behalf of maphew
This commit is contained in:
parent
8f421b64f1
commit
cb8a2edc67
3 changed files with 86 additions and 7 deletions
|
|
@ -0,0 +1,37 @@
|
|||
//go:build cgo
|
||||
|
||||
package embeddeddolt_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestEmbeddedCommitToleratesNothingToCommit is the GH#3886 regression test:
|
||||
// `bd bootstrap` always builds an embedded store (no ServerMode) and, on a
|
||||
// pristine store, calls SetConfig followed by CommitWithConfig with an
|
||||
// otherwise-clean working set. Before this fix, EmbeddedDoltStore.Commit
|
||||
// wrapped ANY DOLT_COMMIT error — including Dolt's benign "nothing to
|
||||
// commit" — as a hard failure, so bootstrap died even though the server
|
||||
// store (DoltStore) has always tolerated the identical case. Both entry
|
||||
// points that alias to Commit (Commit itself and CommitWithConfig) must
|
||||
// succeed here with no working-set changes at all.
|
||||
func TestEmbeddedCommitToleratesNothingToCommit(t *testing.T) {
|
||||
skipUnlessEmbeddedDolt(t)
|
||||
ctx := t.Context()
|
||||
|
||||
t.Run("Commit", func(t *testing.T) {
|
||||
te := newTestEnv(t, "cnt1")
|
||||
// newTestEnv already committed the seed config, so the working set is
|
||||
// clean here: this Commit call has nothing new to stage.
|
||||
if err := te.store.Commit(ctx, "test: nothing to commit"); err != nil {
|
||||
t.Fatalf("Commit on clean working set: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("CommitWithConfig", func(t *testing.T) {
|
||||
te := newTestEnv(t, "cnt2")
|
||||
if err := te.store.CommitWithConfig(ctx, "test: nothing to commit"); err != nil {
|
||||
t.Fatalf("CommitWithConfig on clean working set: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -781,15 +781,25 @@ func (s *EmbeddedDoltStore) ActiveDatabaseSize(ctx context.Context) (int64, erro
|
|||
// Branch, Checkout, CurrentBranch, DeleteBranch, ListBranches are
|
||||
// implemented in version_control.go via versioncontrolops.
|
||||
|
||||
// CommitPending commits all working set changes and reports whether a commit
|
||||
// actually landed. It compares HEAD before and after rather than inspecting
|
||||
// Commit's error: as of GH#3886, Commit itself tolerates Dolt's "nothing to
|
||||
// commit" response (matching the server store) and returns nil for it, so an
|
||||
// error-based check here would report every clean-store call as "committed".
|
||||
func (s *EmbeddedDoltStore) CommitPending(ctx context.Context, actor string) (bool, error) {
|
||||
before, err := s.GetCurrentCommit(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("commit pending: get current commit: %w", err)
|
||||
}
|
||||
msg := fmt.Sprintf("bd: commit pending changes by %s", actor)
|
||||
if err := s.Commit(ctx, msg); err != nil {
|
||||
if issueops.IsNothingToCommitError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
after, err := s.GetCurrentCommit(ctx)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("commit pending: get current commit: %w", err)
|
||||
}
|
||||
return before != after, nil
|
||||
}
|
||||
|
||||
// CommitExists is implemented in version_control.go via versioncontrolops.
|
||||
|
|
|
|||
|
|
@ -98,9 +98,19 @@ func (s *EmbeddedDoltStore) withMutatingPinnedDBConn(ctx context.Context, fn fun
|
|||
return s.withPinnedDBConn(ctx, fn)
|
||||
}
|
||||
|
||||
// Commit stages and commits the full working set. A clean working set is not
|
||||
// an error here: the server store (DoltStore.Commit et al., via
|
||||
// isDoltNothingToCommit) has always tolerated Dolt's "nothing to commit"
|
||||
// response, but this embedded path wrapped it as a hard failure — so `bd
|
||||
// bootstrap`, which builds an embedded store unconditionally and calls
|
||||
// CommitWithConfig (below) right after SetConfig on a pristine, otherwise-clean
|
||||
// store, died on it (GH#3886). Tolerating it here brings embedded to parity.
|
||||
func (s *EmbeddedDoltStore) Commit(ctx context.Context, message string) error {
|
||||
return s.withConn(ctx, true, func(tx *sql.Tx) error {
|
||||
if _, err := tx.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', ?)", message); err != nil {
|
||||
if issueops.IsNothingToCommitError(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("dolt commit: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
|
@ -116,10 +126,32 @@ func (s *EmbeddedDoltStore) CommitWithConfig(ctx context.Context, message string
|
|||
// CommitMergeResolution concludes an operator --strategy merge resolution with
|
||||
// config included. Embedded Commit already stages everything via DOLT_COMMIT
|
||||
// ('-Am'), so config is never dropped here the way server-mode Commit drops it
|
||||
// (GH#2455); this alias satisfies the VersionControl interface so cmd/bd can
|
||||
// conclude bd vc merge --strategy uniformly across both stores.
|
||||
// (GH#2455).
|
||||
//
|
||||
// Unlike Commit/CommitWithConfig, this does NOT alias Commit and does NOT
|
||||
// tolerate a "nothing to commit" response: a merge resolution that leaves the
|
||||
// working set clean is the --ours case, where our values already stood and
|
||||
// resolving the conflict dirtied nothing — DoltStore.CommitMergeResolution
|
||||
// handles exactly this by explicitly concluding the open merge instead of
|
||||
// treating the empty diff as a no-op (concludeOpenMerge, wy-36ilm F12; see
|
||||
// versioncontrolops.mergeInProgress / GetMergeBlockers, whose doc comment notes
|
||||
// this same gap already surfaces as "a raw dolt error from
|
||||
// CommitMergeResolution" for embedded). Swallowing the error here without also
|
||||
// concluding the merge would leave dolt_merge_status.is_merging true while
|
||||
// reporting success, silently re-wedging the next pull/sync — worse than
|
||||
// today's explicit failure. Whether embedded DOLT_COMMIT('-Am') already
|
||||
// concludes an open merge on a clean working set (unlike the server-mode
|
||||
// stored-procedure path, which requires the explicit conclude step) was not
|
||||
// established here, so this keeps the pre-existing non-tolerant behavior
|
||||
// rather than guess (GH#3886 scope: fix bootstrap's plain-Commit path, not
|
||||
// merge conclusion semantics).
|
||||
func (s *EmbeddedDoltStore) CommitMergeResolution(ctx context.Context, message string) error {
|
||||
return s.Commit(ctx, message)
|
||||
return s.withConn(ctx, true, func(tx *sql.Tx) error {
|
||||
if _, err := tx.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', ?)", message); err != nil {
|
||||
return fmt.Errorf("dolt commit: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (s *EmbeddedDoltStore) AddRemote(ctx context.Context, name, url string) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue