Skip to content

Commit 1fb6b95

Browse files
steveyeggeclaude
andcommitted
fix(dolt): auto-commit pending changes before pull to prevent merge errors (GH#2474)
Store initialization (schema init, molecule loading, metadata writes) can dirty the working set before the user's pull command runs. Dolt refuses to merge with uncommitted changes, causing 'cannot merge with uncommitted changes' errors. Repeated failed attempts can corrupt Dolt journals in server mode. Fix: auto-commit any pending changes before executing pull in both Pull() and PullFrom(). Uses existing Commit() which gracefully handles 'nothing to commit' when the working set is already clean. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8386380 commit 1fb6b95

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

internal/storage/dolt/federation.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ func (s *DoltStore) PushTo(ctx context.Context, peer string) error {
3838
// For git-protocol remotes, uses CLI `dolt pull` to avoid MySQL connection timeouts.
3939
// Returns any merge conflicts if present.
4040
func (s *DoltStore) PullFrom(ctx context.Context, peer string) ([]storage.Conflict, error) {
41+
// GH#2474: Auto-commit pending changes before pull to prevent
42+
// "cannot merge with uncommitted changes" errors.
43+
if !s.readOnly {
44+
if err := s.Commit(ctx, "auto-commit before pull"); err != nil {
45+
if !isDoltNothingToCommit(err) {
46+
return nil, fmt.Errorf("failed to commit pending changes before pull: %w", err)
47+
}
48+
}
49+
}
50+
4151
var conflicts []storage.Conflict
4252
if s.isPeerGitProtocolRemote(ctx, peer) {
4353
err := s.withPeerCredentials(ctx, peer, func(creds *remoteCredentials) error {

internal/storage/dolt/store.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,20 @@ func (s *DoltStore) Pull(ctx context.Context) (retErr error) {
14911491
)...),
14921492
)
14931493
defer func() { endSpan(span, retErr) }()
1494+
1495+
// GH#2474: Auto-commit pending changes before pull to prevent
1496+
// "cannot merge with uncommitted changes" errors. Store initialization
1497+
// (schema init, molecule loading, metadata writes) can dirty the working
1498+
// set before the user's pull command runs.
1499+
if !s.readOnly {
1500+
if err := s.Commit(ctx, "auto-commit before pull"); err != nil {
1501+
// "nothing to commit" is fine — working set is already clean
1502+
if !isDoltNothingToCommit(err) {
1503+
return fmt.Errorf("failed to commit pending changes before pull: %w", err)
1504+
}
1505+
}
1506+
}
1507+
14941508
creds := s.mainRemoteCredentials()
14951509
// Git-protocol remotes: use CLI to avoid MySQL connection timeout during transfer.
14961510
// Must check before remoteUser — Hosted Dolt SSH remotes have remoteUser set

0 commit comments

Comments
 (0)