Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pgdevkit/testdb/naming.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import hashlib
import os
import re
import subprocess
from pathlib import Path
Expand All @@ -25,7 +26,15 @@ def slugify(value: str) -> str:


def current_branch(cwd: Path | None = None) -> str:
"""Return the branch checked out in the git worktree rooted at cwd."""
"""Return the branch checked out in the git worktree rooted at cwd.

PGDEVKIT_TESTDB_BRANCH overrides this when set -- lets concurrent CI
checkouts (which all otherwise resolve to detached-HEAD "HEAD") get
distinct database names on a shared test-DB container.
"""
override = os.environ.get("PGDEVKIT_TESTDB_BRANCH")
if override:
return override
result = subprocess.run(
["git", "rev-parse", "--abbrev-ref", "HEAD"],
cwd=cwd,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ packages = ["pgdevkit"]

[project]
name = "pgdevkit"
version = "0.7.1"
version = "0.7.2"
description = "A helper for developing with Postgres"
readme = "README.md"
requires-python = ">=3.14"
Expand Down
8 changes: 8 additions & 0 deletions tests/testdb/test_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def test_current_branch_reads_the_checked_out_branch(tmp_path: Path):
assert current_branch(tmp_path) == "my-feature"


def test_current_branch_env_override_skips_git_entirely(tmp_path: Path, monkeypatch):
# Not a git repo at all -- the override must short-circuit before the
# `git rev-parse` subprocess call, which would otherwise raise.
monkeypatch.setenv("PGDEVKIT_TESTDB_BRANCH", "ci-job-42")

assert current_branch(tmp_path) == "ci-job-42"


def _init_repo(repo: Path, initial_branch: str) -> None:
repo.mkdir()
subprocess.run(["git", "init", "-q"], cwd=repo, check=True)
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading