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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <key>` — 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 `<root>/.workspace/.cache/<namespace>/<key>` with a self-managed `.gitignore`. The hook runner injects `GIT_WORKSPACE_CACHE_NAMESPACE=hooks/<hook_name>` for bin-script hooks.
- `GIT_WORKSPACE_CACHE_DIR` environment variable injected into hook execution environments — points to `<root>/.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

Expand Down
10 changes: 9 additions & 1 deletion src/git_workspace/env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
from collections.abc import Callable
from typing import TYPE_CHECKING

Expand All @@ -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)),
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading