Skip to content

Atoms Overview

Every registered scenario is built from small, single-purpose atoms — functions that take a TempGitRepo and apply one side-effect. The atom signature is uniform:

type Step = (repo: TempGitRepo) => Promise<void>

Atoms compose via chain(...):

import { chain, addCommit, switchToBranch, startMerge } from '@gfargo/git-scenarios'
const setup = chain(
addCommit({ message: 'base', files: { 'x.ts': 'base\n' } }),
switchToBranch('feat/theirs'),
addCommit({ message: 'theirs', files: { 'x.ts': 'theirs\n' } }),
switchToBranch('main'),
addCommit({ message: 'ours', files: { 'x.ts': 'ours\n' } }),
startMerge('feat/theirs'),
)
// Use it:
const repo = await createTempGitRepo()
await setup(repo)

Atom categories

CategoryAtoms
Control Flowchain, repeat, conditionally
Working TreewriteFiles, deleteFiles, renameFile, seededFiles
Commits & StagingstageFiles, commit, addCommit, emptyCommit, amendCommit
Branches & TagsswitchToBranch, checkoutBranch, createBranch, deleteBranch, createTag, deleteTag
Remotes & TrackingaddRemote, removeRemote, renameRemote, setUpstream, setRemoteRef
OperationsstartMerge, cherryPick, revert, startRebase, startBisect, resetTo, …
ScopingonBranch, insideSubmodule, withAuthor, withRemoteTracking
UtilitiesenableSparseCheckout, shallowAt, addNote, installHook, setConfig, daysAgo

Writing custom atoms

Any function that returns a Step is an atom:

import type { Step } from '@gfargo/git-scenarios'
function myCustomAtom(arg: string): Step {
return async (repo) => {
await repo.git.raw(['some-command', arg])
}
}
// Use it alongside built-in atoms:
await chain(
addCommit({ message: 'init', files: { 'README.md': '# repo' } }),
myCustomAtom('value'),
)(repo)