diff --git a/CHANGELOG.md b/CHANGELOG.md index 0322f97..46e3486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added - `git workspace cache get|set|exists ` — file-based cache scoped by the `GIT_WORKSPACE_CACHE_NAMESPACE` env var; intended for use inside hook scripts to skip already-completed work (e.g. paired with `GIT_WORKSPACE_FINGERPRINT_*` to gate `uv sync`). Cache lives at `/.workspace/.cache//` with a self-managed `.gitignore`. The hook runner injects `GIT_WORKSPACE_CACHE_NAMESPACE=hooks/` for bin-script hooks. - `GIT_WORKSPACE_CACHE_DIR` environment variable injected into hook execution environments — points to `/.workspace/.cache`, useful for direct cache manipulation (e.g. invalidation via `rm -rf "$GIT_WORKSPACE_CACHE_DIR"`). +- `GIT_WORKSPACE_BRANCH_SLUG` environment variable — branch name lowercased with non-alphanumeric runs collapsed to `-` (e.g. `feat/GWS-001` → `feat-gws-001`); useful for URL-safe identifiers like container or namespace names. ### Changed - Copy assets are now rendered as [Jinja2](https://jinja.palletsprojects.com/) templates instead of regex placeholder substitution; existing `{{ GIT_WORKSPACE_* }}` files render identically, but `{% if %}` / `{% for %}` / filters are now supported for richer control over the output. Unknown variables still render verbatim; only `GIT_WORKSPACE_*` keys are exposed to templates. `git workspace doctor` flags malformed templates as errors. +- **Breaking:** `GIT_WORKSPACE_BRANCH_NO_SLASH` renamed to `GIT_WORKSPACE_BRANCH_SNAKE` and now produces true snake_case — lowercased with non-alphanumeric runs collapsed to `_` (e.g. `feat/GWS-001` → `feat_gws_001`). Previously it preserved case and only replaced `/` with `_`. Migrate by renaming references and updating any consumers that depended on the original casing or characters being preserved. ## [0.6.0] - 2026-04-26 diff --git a/src/git_workspace/env.py b/src/git_workspace/env.py index 7186f6f..b7c8fa2 100644 --- a/src/git_workspace/env.py +++ b/src/git_workspace/env.py @@ -1,4 +1,5 @@ import os +import re from collections.abc import Callable from typing import TYPE_CHECKING @@ -9,7 +10,14 @@ _BASE_VAR_BUILDERS: tuple[tuple[str, Callable[[Worktree], str]], ...] = ( ("GIT_WORKSPACE_BRANCH", lambda wt: wt.branch), - ("GIT_WORKSPACE_BRANCH_NO_SLASH", lambda wt: wt.branch.replace("/", "_")), + ( + "GIT_WORKSPACE_BRANCH_SNAKE", + lambda wt: re.sub(r"[^a-z0-9]+", "_", wt.branch.lower()).strip("_"), + ), + ( + "GIT_WORKSPACE_BRANCH_SLUG", + lambda wt: re.sub(r"[^a-z0-9]+", "-", wt.branch.lower()).strip("-"), + ), ("GIT_WORKSPACE_ROOT", lambda wt: str(wt.workspace.dir)), ("GIT_WORKSPACE_NAME", lambda wt: wt.workspace.dir.name), ("GIT_WORKSPACE_BIN", lambda wt: str(wt.workspace.paths.bin)), diff --git a/tests/unit/test_env.py b/tests/unit/test_env.py index adda9e3..eb1a7c8 100644 --- a/tests/unit/test_env.py +++ b/tests/unit/test_env.py @@ -32,9 +32,13 @@ def test_sets_branch(self, worktree: MagicMock) -> None: env = build_env(worktree) assert env["GIT_WORKSPACE_BRANCH"] == BRANCH - def test_sets_branch_no_slash(self, worktree: MagicMock) -> None: + def test_sets_branch_snake(self, worktree: MagicMock) -> None: env = build_env(worktree) - assert env["GIT_WORKSPACE_BRANCH_NO_SLASH"] == BRANCH.replace("/", "_") + assert env["GIT_WORKSPACE_BRANCH_SNAKE"] == "feat_gws_001" + + def test_sets_branch_slug(self, worktree: MagicMock) -> None: + env = build_env(worktree) + assert env["GIT_WORKSPACE_BRANCH_SLUG"] == "feat-gws-001" def test_sets_root(self, worktree: MagicMock) -> None: env = build_env(worktree)