collide

package
v0.31.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package collide finds semantic collisions between branches that git merges cleanly (#522): two tasks that each add migration 005 under different file names, say. git sees two new files; the project sees two migrations claiming one place in the sequence, and breaks after both are merged.

A Rule (semantic_checks in .orchestrator/config.yaml) names files by glob and says how to read an identity from them. Only what a branch adds is looked at — the files it adds relative to where it left the base, minus any the base already has at the same path — so a rule never fires on what was already there. Everything is read with git from the repository, no checkout is touched, and no dependency beyond git is needed.

Index

Constants

View Source
const (
	// KindSequence reads an identity from the NAME of each file a branch
	// adds: migration numbers.
	KindSequence = "sequence"
	// KindUniqueKey reads an identity from each LINE a branch adds to a
	// watched file: endpoint paths, config keys, Alembic down_revisions.
	KindUniqueKey = "unique_key"
	// KindCommand runs a project script; a non-zero exit is a collision.
	KindCommand = "command"
)

Rule kinds (docs/design/issue-522-merge-queue.md §3.3).

View Source
const (
	ModeBlock = "block"
	ModeWarn  = "warn"
	ModeOff   = "off"
)

Modes: block stops a merge, warn records the collision, off skips the rule.

Variables

This section is empty.

Functions

This section is empty.

Types

type Branch

type Branch struct {
	Label string
	Ref   string
}

Branch is another open branch to compare with, and how to name it.

type Collision

type Collision struct {
	Rule string `json:"rule"`
	Key  string `json:"key"`
	// File is the branch's file.
	File string `json:"file"`
	// With is "base" or the other branch's label; WithFile its file, empty
	// for a contiguity gap.
	With     string `json:"with"`
	WithFile string `json:"with_file,omitempty"`
	Mode     string `json:"mode"`
	Reason   string `json:"reason"`
}

Collision is one identity a branch adds that the base, or another branch, already claims.

func Check

func Check(ctx context.Context, repo string, rules []Rule, base Branch, head string, others []Branch) ([]Collision, error)

Check runs rules over what head adds, against base and against what each of others adds. Refs are anything git rev-parse takes; base's Label is how the reasons name it.

type Rule

type Rule struct {
	Name string `yaml:"name"`
	// Kind is how the rule reads an identity (KindSequence).
	Kind string `yaml:"kind"`
	// Paths are the globs the rule watches, repository-relative; `**`
	// crosses directories.
	Paths []string `yaml:"paths"`
	// Key is a regular expression over a watched file's NAME; its first
	// group is the identity, \d+ for a sequence number.
	Key string `yaml:"key"`
	// Contiguous also requires a sequence's new numbers to follow the base's
	// highest one with no gap.
	Contiguous bool `yaml:"contiguous"`
	// Pattern is a unique_key rule's regular expression over each added
	// line; its first group is the identity.
	Pattern string `yaml:"pattern"`
	// Run is a command rule's shell command, run in the repository with
	// ORCH_BASE_SHA, ORCH_HEAD_SHA and ORCH_OTHER_HEADS (space-separated)
	// set; a non-zero exit is a collision, its output the detail.
	Run string `yaml:"run"`
	// Mode is block, warn or off; empty is warn.
	Mode string `yaml:"mode"`
}

Rule is one semantic_checks entry.

func AlembicRule

func AlembicRule(versionsDir string) Rule

AlembicRule is the unique_key rule for an Alembic versions directory (#522 decision 4): Alembic chains migrations by down_revision, so two new migrations naming the same parent are two heads, whatever their files are called.

func DefaultRules

func DefaultRules(root string) []Rule

DefaultRules are the migration rules for the stacks a repository already shows, for `orch init` to write (#522 decision 4): Alembic (by down_revision), Django (one sequence per app), Supabase and a plain db/migrations directory of numbered SQL files. Empty when it shows none — most often a repository scaffolded before its code exists.

func (Rule) Validate

func (r Rule) Validate() error

Validate reports what makes the rule unusable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL