beads/cmd/bd/dolt_autocommit.go
gascity-eddie[bot] 8d2b4152f7
fix: commit server-mode config and memory writes (GH#4078, carries #4383) (follow-up to #7299) (#7608)
* feat(storage): add CommitConfigOnly — scoped config-table commit (GH#4078)

Generic Commit() excludes the config table by design (GH#2455) and
CommitWithConfig stages everything via '-Am' — neither can commit an
intentional config write without sweeping concurrent operations' dirty
tables in server mode. CommitConfigOnly stages ONLY config (via the
existing doltAddAndCommit helper) and commits it.

- VersionControl interface method with GH#4078/GH#2455 rationale
- DoltStore: scoped DOLT_ADD('config') + DOLT_COMMIT
- EmbeddedDoltStore: aliases Commit — single-process, so '-Am' cannot
  sweep concurrent work (same rationale as its CommitWithConfig alias)
- Tests against a real dolt-sql-server container: scoped commit lands,
  concurrent dirty issues row survives uncommitted, and generic
  Commit()'s config exclusion is pinned as a regression guard

(cherry picked from commit 61ba8f05c9)
Carry note: rebased onto b1bee123b. The two version_control.go conflicts
were additive (upstream added CommitMergeResolution/CommitAll in the same
spot); resolved by keeping both sides, no change to this commit's code.

* feat(storage): CommitConfigUserKVOnly — screen memory commits to kv.* rows (GH#4078)

Carry reconciliation for the #4383 review: CommitConfigOnly stages the whole
config table, so a memory write's commit in server mode could sweep a
concurrent writer's half-applied internal key (issue_prefix above all), the
row-level form of the GH#2455 hazard. The review asked for #4412's kv.*
screen at the remember/forget sites.

CommitConfigUserKVOnly applies that screen before the scoped commit: if any
dirty config row is outside kv.*, it commits nothing and names the keys,
pointing at `bd dolt commit` (CommitAll), the same remedy the pre-pull
refusal gives. User kv.* rows already dirty are committed with the memory,
as the pre-pull auto-commit would. The screen query moves out of
assertDirtyConfigUserKVOnly into dirtyInternalConfigKeys so both paths share
it; the pre-pull refusal text is unchanged. Embedded aliases Commit, as its
CommitConfigOnly does.

Also softens the CommitConfigOnly interface doc (review nit): embedded mode
commits the whole working set, not only config.

Tests (server container): user kv.* rows commit; a dirty internal key is
refused with HEAD and the working set untouched.

* fix(storage): stage config's lookup-table projections with CommitConfigOnly (GH#4078)

Carry reconciliation for a change on main since #4383 was written:
SetConfig now writes status.custom into custom_statuses and types.custom into
custom_types in the same transaction as the config row (SyncConfigTables),
and reads of those sets are table-first. CommitConfigOnly staged config
alone, so `bd config set status.custom ...` in server mode would commit the
row and leave its projection dirty: HEAD would carry the new string with the
old lookup set, the split the projection exists to prevent. The
transactional SetConfig already marks the synced table dirty for this reason.

CommitConfigOnly now stages config plus issueops.ConfigProjectionTables(),
a list kept next to SyncConfigTables. Clean tables stage nothing, and the
projections are written only from config, so no other kind of work is
swept. CommitConfigUserKVOnly keeps staging config alone: memory rows have
no projection.

Test (server container): status.custom and types.custom writes leave
config, custom_statuses and custom_types all clean after CommitConfigOnly.

* fix(cli): commit config writes in server mode — remember/forget/config set (GH#4078)

In server mode nothing ever commits config-table writes: maybeAutoCommit
skips SQL-server modes entirely, and the explicit flush commands call
Commit(), which excludes config (GH#2455) and silently no-ops on a
config-only working set. Every bd remember / bd config set then strands
the working set dirty and the next 'bd dolt pull' fails with 'cannot
merge with uncommitted changes' until a manual raw-SQL flush.

commitConfigWrite commits the config table immediately after an
intentional config write, scoped via CommitConfigOnly so concurrent
operations' dirty tables are never swept. Server modes only — embedded
'-Am' auto-commit and the unflagged-writes sweep already cover config.
This restores the v1.0.1 always-commit behavior from PR #3052 that the
unified-PostRun refactor regressed.

Wired sites: bd remember, bd forget, bd config set, bd config unset,
bd config set-many (one commit for the whole batch). Commit failures
surface loudly per each site's error convention.

(cherry picked from commit 64f77a1963)
Carry note: rebased onto b1bee123b. config set/unset now write through the
WorkspaceConfig role and remember/forget through the memoryops role, so the
conflict resolution re-anchors each commitConfigWrite call right after that
site's noteDirectConfigWrite/noteDirectMemoryWrite (set-many: after its
direct-route store.SetConfig loop) and uses each RunE's current error
convention (return HandleError / HandleErrorRespectJSON instead of os.Exit).
No change to commitConfigWrite or its tests in this commit.

* fix(cli): reconcile commitConfigWrite with current main (GH#4078)

Carry reconciliation on top of the cherry-picked commit, for two things
that changed on main since #4383 was written:

- Proxied route: proxied mode never opens a store, and its WorkspaceConfig
  and memory roles commit each write inside their own unit of work
  (noteDirectConfigWrite / noteDirectMemoryWrite say so). commitConfigWrite
  now returns early on usesProxiedServer() instead of relying on the nil
  store, and the proxied test asserts the no-op.
- dolt.auto-commit: bd-4wamg made batch/off real deferral in server mode,
  and #5830 made `bd dolt commit` commit config (CommitAll). A config write
  under batch/off now defers with every other server-mode write instead of
  committing regardless; mode on (the default) commits as before. This
  matches embedded mode, where the PersistentPostRun auto-commit honors the
  same setting.

The doc comment drops the stale "-Am auto-commit and unflagged-writes
sweep" wording and says why rename-prefix and migrate are not wired.

* fix(cli): commit remember/forget through the kv.*-screened variant (GH#4078)

Carry reconciliation for the #4383 review: bd remember and bd forget write
user kv.* data, so their server-mode commit now goes through
CommitConfigUserKVOnly via a new commitMemoryWrite helper. A dirty internal
config key from another writer is refused with the keys named and the
`bd dolt commit` remedy, instead of being swept into the memory's commit.
bd config set/unset/set-many keep CommitConfigOnly: the operator is writing
config deliberately there, the same trust level as `bd dolt commit`.

commitConfigWrite and commitMemoryWrite share one guard path
(commitConfigTable), so both no-op on embedded, proxied, and batch/off.

* docs: changelog entries for the GH#4078 config-commit fixes

Server-mode config writes (bd remember/forget, config set/unset/set-many)
now commit immediately via the scoped CommitConfigOnly, and the explicit
'bd dolt commit'/'bd vc commit' are config-inclusive and truthful.

(cherry picked from commit c412b96b96)
Carry note: rebased onto b1bee123b. The hunk's old context now sits in a
released section, so it is moved under [Unreleased] > Fixed. The second
entry (bd dolt commit / bd vc commit) is dropped: that fix landed separately
as #5830 (CommitAll) and is already in the changelog.

* docs(changelog): update the GH#4078 entry for the carried fix

Rewords the cherry-picked entry for what the fix does on today's main:
batch/off defer config writes like every other server-mode write, the
commit stages config's lookup-table projections, remember/forget are
screened to kv.*, and #4412's pre-pull commit now absorbs dirty kv.* rows,
so the pull-side symptom is a refusal on internal keys rather than the
merge error. Drops the #2455 link, which does not resolve in this repo
(the number is a source-comment reference).

* test(cli): pin server-mode config writes leave no config dirt (GH#4078)

User-level regression test for the carried fix, on the direct SQL-server
route against the suite's Dolt server: bd remember, bd config set
(status.custom), bd config set-many (types.custom + status.custom), bd
config unset and bd forget must each leave config, custom_statuses and
custom_types clean in dolt_status. A final step dirties an internal config
key out of band and checks that bd remember refuses, names the key, and
leaves config dirty for bd dolt commit.

On b1bee123b (without the fix) it fails at its first step:
  after bd remember --key gh4078 server-mode memory: config left
  uncommitted in the working set (GH#4078)
With memory writes routed through the unscreened commit, it fails at the
last step: bd remember committed over a dirty internal config key.

* docs(cli): say why config writes skip the kv.* screen (GH#4078)

commitConfigWrite stages every dirty config row, while commitMemoryWrite
refuses internal keys. Record the reason in the code, not only in the
commit history: bd config set/unset/set-many are deliberate config
writes, the same trust level as bd dolt commit.

* build(bazel): list the GH#4078 test files in BUILD srcs

The rows the Bazel / test job's 'BUILD files in sync' check printed at ec27abd1d. Without them the Bazel tiers never run config_commit_write_test.go, config_commit_server_integration_test.go or commit_config_test.go, and the server-Dolt storage tier fails its shard check for the six storage tests.

* fix(storage): say the kv.* write is already saved when the screen refuses (GH#4078)

When CommitConfigUserKVOnly refuses, the memory row's SQL transaction has already committed, so exit 1 read as 'not stored'. The refusal now says the write is in the working set and that bd dolt commit publishes it with those keys.

* fix(httpclient): add the scoped config commits to the no-op commit family

The PR adds CommitConfigOnly and CommitConfigUserKVOnly to
storage.VersionControl. Since the PR's merge base, main added
internal/httpclient, whose Store asserts storage.DoltStorage, so the
tree merged with main did not build (*Store does not implement
storage.DoltStorage: missing method CommitConfigOnly).

Add both methods to httpclient's commit family as no-ops, for that
family's D3 reason: a write over this client is durable once the server
answers, so there is nothing to flush, and refusing would fail a command
whose write already landed. Regenerate unsupported_gen.go: only its
trailer count moves (201 -> 203 methods), because both methods are
hand-written rather than stubbed. Extend the two tests that pin the
family by name, TestCommitFamilyIsNoOp and
TestCommitFamilyIsNotOnTheUnsupportedMap, to cover both methods.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Eddie the Engineer
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: sms <114885497+seanmartinsmith@users.noreply.github.com>

* fix(config): screen the staged set, warn on refused memory commits (GH#4078)

Review fixes for the adopted PR, iterations 1 and 2.

CommitConfigUserKVOnly screened the working set on one pooled
connection and staged config on another, so an internal key written in
between (issue_prefix above all) was committed with a memory: the
GH#2455 hazard the screen exists to refuse. The screen, DOLT_ADD and
DOLT_COMMIT now share one pinned connection (stageAndCommit), and the
screen runs twice: on the working set before DOLT_ADD, and on what
DOLT_ADD actually staged after it, because sessions on one branch share
the working set. A refusal after staging unstages config again with
DOLT_RESET, so the refused rows are not left staged for the next commit
on the branch. Two residuals are documented at the code: another commit
path's own DOLT_ADD of config landing between the second screen and
DOLT_COMMIT is absorbed, as for every scoped commit, and the table-wide
reset can unstage such a commit's config staging. The refusal is now a
*storage.ConfigCommitRefusedError carrying the keys.

The two config-table commits also stop widening their staging list
with the versioned-history tables: a config write mints no version
rows, and that list's issues table swept concurrent issue work into a
config or memory commit.

bd remember and bd forget exited 1 after their write had landed
whenever a non-kv.* config key was dirty, including keys bd's own
unwired writers leave, such as the issue_prefix of bd rename-prefix.
They now warn on stderr with the keys named and exit 0, as v1.0.1
(#3052) did on a failed memory commit. Under --json they add
committed: false, commit_error and dirty_config_keys, only when the
commit did not happen, so a committed write's payload keeps its shape.
The CHANGELOG entry now says so instead of claiming that the refusal
restores the v1.0.1 behavior.

bd config unset of a yaml-only secret key deleted the credential row an
older bd had stored, but never committed the delete, so HEAD, which
bd dolt push publishes, kept the credential while --json reported
database_row_removed. The delete is now committed like any other config
write. A failed commit is a warning, and database_commit_failed under
--json, because the delete and the YAML unset both landed.

A commit error the store marks storage.ErrCommitIndeterminate, such as
a connection lost during DOLT_COMMIT, may have landed, so neither
surface reports it as a definite non-commit any more. --json adds
commit_indeterminate (remember, forget) or
database_commit_indeterminate (the secret-row unset) beside
committed: false and database_commit_failed, which stay, so a consumer
that reads only those is still told to commit; the secret-row warning
and the note a failed YAML unset carries say the removal may not be
committed and point at bd dolt commit.

commitConfigWrite's doc now says why a failed commit fails the config
verbs while the memory verbs only warn, and names bd kv set/clear and
the kv.memory rows bd import writes as config writes it does not wire
yet. CommitWithConfig's interface doc drops bd config set, which on
the SQL-server route now commits through CommitConfigOnly, and points a
command committing only its own config write at the scoped commits.

Tests: a live-store test writes an internal key between the screen and
DOLT_ADD and requires a refusal that moves no HEAD and leaves nothing
staged; a sqlmock test pins the refusal SQL, including a failed
unstage; a versioned-history-on test requires a dirty issues table to
stay dirty through both scoped commits; cmd/bd fakes pin the
warn-and-succeed contract, the JSON fields, the secret-row commit, and
the indeterminate qualifiers in both payloads and both texts; and the
server E2E gains a secret-row step plus a bd rename-prefix step ahead
of bd remember and bd forget.

Pre-approval CI repair: tools/nogo/unvalidated_integration_tests.txt
now lists the PR's integration-tagged
cmd/bd/config_commit_server_integration_test.go. Since #7486 no nogo
lane analyzes integration-tagged test files, and
TestUnvalidatedIntegrationTestsFileIsExact requires the list to name
every one of them, so the new file failed //scripts:nogo_integration_scan_test
in the Bazel test and integration lanes.

Left for follow-ups, both pre-existing and not changed here: the
review's projection minor (config delete paths do not reconcile
custom_statuses/custom_types), and committing bd kv set/clear and
bd import's kv.memory rows on the SQL-server route.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: sms <114885497+seanmartinsmith@users.noreply.github.com>

---------

Co-authored-by: Aaron Lippold <lippold@gmail.com>
Co-authored-by: sms <114885497+seanmartinsmith@users.noreply.github.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <julianknutsen@users.noreply.github.com>
2026-10-16 13:48:30 +00:00

296 lines
11 KiB
Go

package main
import (
"context"
"fmt"
"slices"
"strings"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/issueops"
)
// transact wraps store.RunInTransaction and marks that a transactional
// DOLT_COMMIT occurred, preventing the redundant maybeAutoCommit in
// PersistentPostRun. Use this instead of calling store.RunInTransaction
// directly from command handlers.
func transact(ctx context.Context, s storage.DoltStorage, commitMsg string, fn func(tx storage.Transaction) error) error {
err := s.RunInTransaction(ctx, commitMsg, fn)
if err == nil {
commandDidExplicitDoltCommit = true
}
return err
}
// transactHonoringAutoCommit wraps transactional CLI writes whose Dolt commit is
// part of command auto-commit policy. In batch/off modes the SQL transaction
// still commits, but no Dolt version commit is created — the blank message
// makes StageAndCommit a no-op, in embedded and SQL-server mode alike
// (bd-4wamg: batch used to be silently inert in server mode).
func transactHonoringAutoCommit(ctx context.Context, s storage.DoltStorage, commitMsg string, fn func(tx storage.Transaction) error) error {
msg := commitMsg
committedExplicitly := strings.TrimSpace(msg) != ""
commitNow, err := writesCommitNow()
if err != nil {
return err
}
if !commitNow {
msg = ""
committedExplicitly = false
}
err = s.RunInTransaction(ctx, msg, fn)
if err == nil && committedExplicitly {
commandDidExplicitDoltCommit = true
}
return err
}
// writesCommitNow reports whether a CLI write should create its Dolt version
// commit as part of the write (mode "on"), rather than leaving it in the
// working set for a later explicit commit point (batch/off; bd dolt commit).
// An unset value means no Dolt store resolved a default (e.g. a non-Dolt
// backend), where per-write version commits are the only behavior that
// exists — treat it as "on".
func writesCommitNow() (bool, error) {
if strings.TrimSpace(doltAutoCommit) == "" {
return true, nil
}
mode, err := getDoltAutoCommitMode()
if err != nil {
return false, err
}
return mode == doltAutoCommitOn, nil
}
// embeddedWritesCommitNow is writesCommitNow for the embedded-only commit
// points (the PersistentPostRun working-set flush and create's post-write
// flush). In SQL-server mode those flushes never run — mode "on" writes
// version themselves inside the storage layer.
func embeddedWritesCommitNow() (bool, error) {
if !isEmbeddedMode() {
return false, nil
}
return writesCommitNow()
}
// issueOpsContext applies command auto-commit policy to the context a write verb
// hands the issue-operations facade. The facade creates its Dolt version commit
// inside the storage layer, so batch mode cannot blank a commit message the way
// transactHonoringAutoCommit does — it has to say so on the context instead.
// This is mode-driven, not embedded-only: in SQL-server mode the storage
// layer's per-write commit sites honor the same deferral (bd-4wamg).
func issueOpsContext(ctx context.Context) (context.Context, error) {
commitNow, err := writesCommitNow()
if err != nil {
return nil, err
}
if commitNow {
return ctx, nil
}
return issueops.WithDeferredVersionCommit(ctx), nil
}
// explicitCommitPointContext clears the dolt.auto-commit deferral for a proxied
// dual whose direct-route twin is an explicit commit point.
//
// The direct route encodes two commit classes, and it encodes them by which
// wrapper a verb picks: writes whose Dolt commit is auto-commit policy go
// through transactHonoringAutoCommit or issueOpsContext above, while the
// explicit commit points go through transact and mint a Dolt commit carrying
// the caller's message whatever the policy says. The proxied route has no such
// choice to make per verb — it applies the policy ONCE, to rootCtx in the root
// pre-run (GH#4995) — so the second class has to opt back out here, or
// doltServerTx.Commit blanks the message it was given: a proxied
// `bd batch -m "release batch"` under dolt.auto-commit=batch would persist the
// rows, discard the message and mint nothing, while the identical command and
// config on the direct route commits it.
//
// Scope is the intersection of two in-tree lists: the transact() call sites,
// and the paths the proxied front door permits (proxyPermittedPaths in
// capability_registry.go). That is batch, mol bond/pour/squash, mol wisp create
// and the WISP half of mol burn; cook and migrate issues also call transact but
// are refused in proxied mode, so they have no dual to exempt.
//
// Membership is per commit site, not per command: mol burn's persistent half
// reaches deleteBatch -> issueOpsContext on the direct route, which is the
// policy-honoring class, so runMolBurnProxiedServer exempts only the wisp
// transaction. TestProxiedDualsExemptTheirExplicitCommitPoints pins both arms.
func explicitCommitPointContext(ctx context.Context) context.Context {
return issueops.WithImmediateVersionCommit(ctx)
}
type doltAutoCommitParams struct {
// Command is the top-level bd command name (e.g., "create", "update").
Command string
// IssueIDs are the primary issue IDs affected by the command (optional).
IssueIDs []string
// MessageOverride, if non-empty, is used verbatim.
MessageOverride string
}
// maybeAutoCommit creates a Dolt commit after a successful write command when enabled.
//
// Semantics:
// - Only applies when dolt auto-commit is "on" AND the active store is versioned (Dolt).
// - Skips SQL server modes; the server owns transaction commit lifecycle there.
// - In "batch" mode, commits are deferred — changes accumulate in the working set
// until an explicit commit point (bd dolt commit).
// - Uses Dolt's "commit all" behavior under the hood (DOLT_COMMIT -Am).
// - Treats "nothing to commit" as a no-op.
func maybeAutoCommit(ctx context.Context, p doltAutoCommitParams) error {
if !isEmbeddedMode() {
return nil
}
return maybeAutoCommitStore(ctx, getStore(), p)
}
func commitPendingIfEmbedded(ctx context.Context, st storage.DoltStorage, actor string, p doltAutoCommitParams) error {
if !isEmbeddedMode() || st == nil {
return nil
}
if strings.TrimSpace(p.MessageOverride) == "" {
p.MessageOverride = formatDoltAutoCommitMessage(p.Command, actor, p.IssueIDs)
}
return maybeAutoCommitStore(ctx, st, p)
}
// commitConfigWrite creates the Dolt commit for an intentional config-table
// write on the direct SQL-server route (bd config set/unset/set-many; bd
// remember/forget go through commitMemoryWrite). Nothing else commits it there
// (GH#4078): the store-level writes those verbs reach through their roles
// commit the SQL transaction only, maybeAutoCommit returns early off the
// embedded route, and plain Commit excludes config anyway (GH#2455).
// CommitConfigOnly stages ONLY the config table, so a concurrent operation's
// other dirty tables are never swept.
//
// It is a no-op wherever something else already owns that commit: embedded
// mode (the PersistentPostRun auto-commit stages config with everything
// else), the proxied route (the role's unit of work commits each write), and
// dolt.auto-commit batch/off, which defer it to `bd dolt commit` (CommitAll,
// config included) exactly as they defer every other server-mode write.
//
// Unlike commitMemoryWrite it does not screen other dirty config rows: the
// operator is writing config on purpose, the trust level of `bd dolt commit`.
// The config verbs return a failed commit as the command's failure, where
// remember and forget only warn: a memory commit is refused whenever another
// writer left an internal key dirty, so exit 1 there would be routine for a
// write that landed, while this commit is never refused and fails only on a
// genuine error, which its "committing config write" prefix attributes to the
// commit rather than the write. (config unset's delete of a leaked secret row
// warns too: the YAML unset is that command's contract.)
// rename-prefix and migrate also write config (issue_prefix, sync.branch) and
// are deliberately not wired here: they are multi-step operations, and when
// their config row should become a commit is the GH#2455 question itself.
// `bd kv set`/`clear` and the kv.memory rows `bd import` writes are not wired
// here yet either, so on this route they stay in the working set until a later
// commit stages config, such as `bd dolt commit`.
func commitConfigWrite(ctx context.Context, st storage.DoltStorage, command string) error {
if err := commitConfigTable(ctx, st, command, storage.DoltStorage.CommitConfigOnly); err != nil {
return fmt.Errorf("committing config write: %w", err)
}
return nil
}
// commitMemoryWrite is commitConfigWrite for bd remember/forget. A memory is
// user kv.* data, so its commit takes only kv.* config rows with it
// (CommitConfigUserKVOnly): a dirty internal key is refused, not swept in. The
// refusal is a *storage.ConfigCommitRefusedError naming the keys, and the
// callers report it as a warning: by then the memory write has landed.
func commitMemoryWrite(ctx context.Context, st storage.DoltStorage, command string) error {
if err := commitConfigTable(ctx, st, command, storage.DoltStorage.CommitConfigUserKVOnly); err != nil {
return fmt.Errorf("committing memory write: %w", err)
}
return nil
}
func commitConfigTable(ctx context.Context, st storage.DoltStorage, command string,
commit func(storage.DoltStorage, context.Context, string) error) error {
if isEmbeddedMode() || usesProxiedServer() || st == nil {
return nil
}
commitNow, err := writesCommitNow()
if err != nil {
return err
}
if !commitNow {
return nil
}
if lm, ok := storage.UnwrapStore(st).(storage.LifecycleManager); ok && lm.IsClosed() {
return nil
}
msg := formatDoltAutoCommitMessage(command, getActor(), nil)
if err := commit(st, ctx, msg); err != nil && !isDoltNothingToCommit(err) {
return err
}
return nil
}
func maybeAutoCommitStore(ctx context.Context, st storage.DoltStorage, p doltAutoCommitParams) error {
mode, err := getDoltAutoCommitMode()
if err != nil {
return err
}
// In batch mode, skip per-command commits. Changes stay in the working set
// and are committed at logical boundaries (bd dolt commit).
if mode != doltAutoCommitOn {
return nil
}
if st == nil {
return nil
}
if lm, ok := storage.UnwrapStore(st).(storage.LifecycleManager); ok && lm.IsClosed() {
return nil
}
msg := p.MessageOverride
if strings.TrimSpace(msg) == "" {
msg = formatDoltAutoCommitMessage(p.Command, getActor(), p.IssueIDs)
}
if err := st.Commit(ctx, msg); err != nil {
if isDoltNothingToCommit(err) {
return nil
}
return err
}
return nil
}
func isDoltNothingToCommit(err error) bool {
return issueops.IsNothingToCommitError(err)
}
func formatDoltAutoCommitMessage(cmd string, actor string, issueIDs []string) string {
cmd = strings.TrimSpace(cmd)
if cmd == "" {
cmd = "write"
}
actor = strings.TrimSpace(actor)
if actor == "" {
actor = "unknown"
}
ids := make([]string, 0, len(issueIDs))
seen := make(map[string]bool, len(issueIDs))
for _, id := range issueIDs {
id = strings.TrimSpace(id)
if id == "" || seen[id] {
continue
}
seen[id] = true
ids = append(ids, id)
}
slices.Sort(ids)
const maxIDs = 5
if len(ids) > maxIDs {
ids = ids[:maxIDs]
}
if len(ids) == 0 {
return fmt.Sprintf("bd: %s (auto-commit) by %s", cmd, actor)
}
return fmt.Sprintf("bd: %s (auto-commit) by %s [%s]", cmd, actor, strings.Join(ids, ", "))
}