Help us shape the future of Go! Take the 2026 Go Developer Survey

migrationgit

package
v0.1.46 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package migrationgit answers, from git, the one question both the version lint and `forge db migration rebase` have to agree on: which migrations were already on the default branch when this branch was cut.

Both callers act on that answer, in opposite directions. The lint flags a migration as NEW — and therefore still fixable — when its version is above the merge-base high-water mark. Rebase REFUSES to re-version a migration that is at or below it and present on the default branch, because renaming one that has already merged breaks every database that recorded it.

Two implementations of that boundary would eventually disagree, and the disagreement would be silent: the lint would tell someone to rebase a file the rebase command would happily rename, or refuse one the lint had just flagged. One definition, in one place.

EVERY FAILURE HERE IS "UNKNOWN", NOT AN ERROR. This code runs in checkouts it does not control: a shallow CI clone, an exported tarball, a repository with no default branch, a migrations directory that is not tracked at all. A missing git binary is deliberately indistinguishable from a failed command, because both mean the same thing to a caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBranchVersions

func DefaultBranchVersions(repoRoot, migrationsDir string) (map[uint64]string, bool)

DefaultBranchVersions returns the migration versions present in migrationsDir on the default branch's tip, mapped to the filename that claims each one.

The TIP, not the merge-base, because this answers "has this version already merged". A migration that landed on main after this branch was cut is just as merged as one that predates it, and renaming it is just as wrong.

func IsTracked

func IsTracked(repoRoot, path string) bool

IsTracked reports whether path is tracked by git, which decides whether a rename goes through `git mv` or a plain filesystem rename.

func MergeBaseMax

func MergeBaseMax(repoRoot, migrationsDir string) (uint64, bool)

MergeBaseMax returns the highest migration version present in migrationsDir as of the merge-base between HEAD and the default branch — the state this branch started from — and whether that could be determined at all.

func Move

func Move(repoRoot, from, to string) error

Move renames from to to, using `git mv` when the source is tracked so the rename is staged as a rename rather than appearing as a delete plus an untracked add.

func RepoRoot

func RepoRoot(dir string) string

RepoRoot returns the git repository root containing dir, or dir itself when there is none. Every git call is scoped to it, so a lookup never reads a parent repository that happens to sit above an untracked project.

Types

This section is empty.

Jump to

Keyboard shortcuts

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