branch

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package branch resolves the current git branch to an isolated ClickHouse workspace database (tr_<branch>). Per ADR 0007 branch databases are schema-only with an explicit lifecycle (no drop-on-merge); this package only computes names — creating and dropping the databases lives in internal/deploy.

Index

Constants

View Source
const Default = "main"

Default is the branch used when git cannot be queried — not a repo, git is absent, or HEAD is detached. main maps to the tr_main production database.

Variables

This section is empty.

Functions

func Current

func Current(ctx context.Context, dir string) (string, error)

Current returns the current git branch for dir via `git -C <dir> rev-parse --abbrev-ref HEAD`.

It is best-effort and always returns a usable name with a nil error: when dir is not a git repo, git is missing, or HEAD is detached (CI often checks out a detached HEAD), it falls back to the TR_BRANCH env override and then to Default ("main"). A non-repo is a documented fallback, not a hard error, so callers always get a name they can hand to DBName.

func DBName

func DBName(branch string) string

DBName maps a git branch to its ClickHouse database name: lowercase, every run of non [a-z0-9_] characters replaced with "_", underscore runs collapsed, leading/trailing "_" trimmed, then prefixed with "tr_". The prefix also makes branches that start with a digit valid CH identifiers.

main               -> tr_main
feature/new-metric -> tr_feature_new_metric
Feature/X          -> tr_feature_x

Types

This section is empty.

Jump to

Keyboard shortcuts

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