expectedTargetSha when you want an optimistic concurrency check before updating the target branch.
Concurrency behavior
merge() has two target-tip modes:
- Provide
expectedTargetShawhen the target branch must still point at a specific commit. If the target moved, the merge fails with409. - Omit
expectedTargetShawhen you want Code Storage to merge into the current target tip. For native Code Storage targets, the gateway may retry stale target or repository movement internally while keeping the originally resolved source commit pinned.
Automatic stale-target retry is disabled for GitHub-backed public targets. Those merges use the
same single-attempt behavior as a strict target-tip guard.
Options
string
required
Source branch name to merge from.
boolean
Set to
true when the source branch lives in the ephemeral namespace.string
required
Target branch name to merge into.
boolean
Set to
true when the target branch lives in the ephemeral namespace.string
required
Merge strategy. Must be one of
merge, ff_only, or ff_prefer.string
Commit SHA that must match the current target tip before the merge is applied. Providing this
field enables strict optimistic concurrency and disables automatic stale-target retry.
string
Optional merge commit message. Used when the backend creates a merge commit.
object
Optional commit identity with
name and email. Required together when provided.object
Optional committer identity with
name and email. Required together when provided.Set to
true to allow merging branches without a shared history.boolean
Collapse the source into a single new commit whose only parent is the current target tip.
Incompatible with the
ff_only strategy.object[]
Ordered per-ref policy rules (
{ pattern, ops? }) embedded in the per-call JWT. First match wins, evaluated against the target ref. Python: ref_policies. Go: RefPolicies with type storage.RefPolicyList. See the Branch Protection guide.Response
string
Merge outcome:
merge_commit, fast_forward, no_op, or unknown. The Python and Go SDKs also
surface squash. The TypeScript SDK normalizes squash to merge_commit for semver
compatibility.string
Commit SHA reported for the merge result.
string
Tree SHA for the resulting commit.
object
Source ref metadata with
branch, ephemeral, and sha.object
Target ref metadata with
branch, ephemeral, and oldSha/old_sha plus newSha/new_sha.string
Merge base SHA when the backend reports one.
number
Number of commits promoted onto the target branch.
Errors
Merge conflicts and retry exhaustion are surfaced asApiError/APIError. The raw error body is
preserved, so callers can inspect conflict_type and any backend fields included with the response.
conflict_type can be:
merge_conflict: Git found file-level conflicts.conflict_pathsandmerge_base_shamay be present.target_moved: the target branch kept moving during automatic retry. Retry the merge later.repo_changed: repository state changed during automatic retry. Retry the merge later.