{"record":{"id":"a945900fe220d42d","repo":"gastownhall/beads","slug":"check-commit-existence-w","errorCode":null,"errorMessage":"check commit existence: %w","messagePattern":"check commit existence: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/version_control.go","lineNumber":90,"sourceCode":"}\n\n// CommitExists checks whether a commit hash (or prefix) exists in dolt_log.\n// Returns false for empty strings or malformed input.\nfunc CommitExists(ctx context.Context, db DBConn, commitHash string) (bool, error) {\n\tif commitHash == \"\" {\n\t\treturn false, nil\n\t}\n\tif err := issueops.ValidateRef(commitHash); err != nil {\n\t\treturn false, nil\n\t}\n\n\tvar count int\n\terr := db.QueryRowContext(ctx, `\n\t\tSELECT COUNT(*) FROM dolt_log\n\t\tWHERE commit_hash = ? OR commit_hash LIKE ?\n\t`, commitHash, commitHash+\"%\").Scan(&count)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"check commit existence: %w\", err)\n\t}\n\treturn count > 0, nil\n}\n\n// Merge merges the named branch into the current branch. The author string\n// should be formatted as \"Name <email>\". Returns any merge conflicts.\n//\n// This runs as a bare DOLT_MERGE under autocommit, so a real conflict makes\n// Dolt reject the implicit transaction (Error 1105: \"@autocommit must be\n// disabled so that merge conflicts can be resolved ...\") before dolt_conflicts\n// can even be inspected — conflicts = error here, same as plain `dolt merge`\n// with no further flags. Callers that want the flag Dolt's error names —\n// resolve-then-commit on conflict — must use MergeWithStrategy instead, which\n// runs the merge on a pinned session with the conflict-tolerant flags set\n// (#4992).\nfunc Merge(ctx context.Context, db DBConn, branch, author string) ([]storage.Conflict, error) {\n\t_, err := db.ExecContext(ctx, \"CALL DOLT_MERGE('--author', ?, ?)\", author, branch)\n\tif err != nil {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/version_control.go#L72-L108","documentation":"CommitExists wraps a failed COUNT(*) query over dolt_log (exact hash or prefix via LIKE) as \"check commit existence: <underlying>\". The library throws it because the existence probe itself failed at the SQL level — it does not mean the commit is absent (that returns (false, nil)). Causes mirror the other dolt_log readers: non-Dolt database, missing dolt_log table, or connection/context failure.","triggerScenarios":"Calling CommitExists on a db without dolt_log (never Dolt-initialized or zero commits); cancelled ctx; broken/stale connection.","commonSituations":"Validating a hash copied from another repo/directory that has no local dolt_log; running during embedded engine startup before the db is ready; wrong database pointed at.","solutions":["Verify the db is Dolt-initialized and has commits (SELECT 1 FROM dolt_log LIMIT 1).","Check you are querying the database that actually contains the commit.","Retry if the wrapped error is transient (connection reset, deadline exceeded).","Treat non-transient unknown-table errors as 'database not initialized' and initialize it before checking hashes."],"exampleFix":"// before\nok, err := versioncontrolops.CommitExists(ctx, db, \"abc123\") // empty/uninitialized db\n// after\n// initialize the Dolt database (dolt init + first commit) first\nok, err := versioncontrolops.CommitExists(ctx, db, \"abc123\")","handlingStrategy":"try-catch","validationCode":"if commitHash == \"\" { return false, nil }\nif err := issueops.ValidateRef(commitHash); err != nil { return false, nil }\nvar n int\nif err := db.QueryRowContext(ctx, \"SELECT 1 FROM dolt_log LIMIT 1\").Scan(&n); err != nil {\n    return false, fmt.Errorf(\"no commit history in this database: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"ok, err := versioncontrolops.CommitExists(ctx, db, hash)\nif err != nil {\n    if strings.Contains(err.Error(), \"check commit existence\") {\n        // treat as 'cannot verify' rather than 'does not exist'\n        return fmt.Errorf(\"existence check unavailable: %w\", err)\n    }\n    return err\n}","preventionTips":["Never treat (false, err) as 'commit missing' — only (false, nil) means verified absence.","Validate the hash with issueops.ValidateRef (the library does this internally and returns false for malformed input).","Ensure the db you probe is the one the commit belongs to (hashes don't span databases).","Call CommitExists after confirming dolt_log is queryable, or you will conflate 'uninitialized' with 'not found'."],"tags":["dolt","sql","commit","validation"],"backgroundTag":"unknown-sql-table","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}