feat(pattern): allow default values for env vars via {.env.X:-fallback} - #139
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #139 +/- ##
==========================================
+ Coverage 41.50% 42.56% +1.06%
==========================================
Files 34 34
Lines 3542 3580 +38
==========================================
+ Hits 1470 1524 +54
+ Misses 2072 2056 -16
🚀 New features to boost your workflow:
|
timvw
force-pushed
the
fix/pattern-variable-defaults
branch
from
August 20, 2026 08:23
555d0e7 to
69e9a21
Compare
Pattern variables referencing unset environment variables now support
bash-style defaults: {.env.WT_CATEGORY:-personal} uses "personal" when
WT_CATEGORY is unset. Without the :- syntax, unset variables still error
(preserving typo detection for misspelled keys).
The implementation preprocesses the pattern string to rewrite
{.env.X:-fallback} into an envOr template function call before
template.Parse, keeping missingkey=error intact for all other variables.
Closes #136
Default values in {.env.X:-fallback} now respect the configured
separator, consistent with how actual env values are transformed.
E.g. with separator="-", {.env.X:-a/b} yields "a-b" when X is unset.
timvw
force-pushed
the
fix/pattern-variable-defaults
branch
from
August 20, 2026 08:34
69e9a21 to
d46a5b4
Compare
timvw
enabled auto-merge (squash)
August 20, 2026 08:34
This was referenced Aug 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{.env.WT_CATEGORY:-personal}usespersonalwhenWT_CATEGORYis unsetseparator(e.g. withseparator = "-",{.env.X:-a/b}yieldsa-b){.brnach}a loud failure rather than a silently mangled pathCloses #136
What this changes
The hard error on a missing variable is intended behaviour and stays. What was missing is a way to opt out of it for a specific variable. The three cases are now:
Previously only the first and third existed. PR #127 documents
{.env.WT_CATEGORY}as the recommended way to group clones by category, so a user who has not exported the variable gets the error correctly but has no way to declare a fallback in the pattern.Syntax:
{.env.X:-fallback}(bash parameter expansion style)The implementation preprocesses the pattern string to rewrite
{.env.X:-fallback}into an internalenvOrtemplate function call beforetemplate.Parse, keepingmissingkey=errorin force for every other reference.Alternatives rejected
{envOr "X" "default"}(template function) — trivially correct but drops the bash-like ergonomics that were asked for.{.env.X | default "default"}(sprig pipeline) — cannot work withmissingkey=error, because the map lookup errors before the pipeline runs. Adopting it would mean relaxing the very option that produces the wanted error.What still errors
{.env.UNSET_VAR}(no:-) — hard error, same as before{.brnach}or any misspelled non-env key — hard error, same as beforeThese are the headline guarantees of this change, and both are pinned by tests.
Scope
Adds the default-value syntax for
{.env.*}references in bothpattern(worktree placement) andrepo_pattern(clone placement). It does not add{.var.X}, a[vars]config section, orwt.var.*git config keys — that is #137. Nor does it address where a per-group value comes from — that is #138. Tracking issue: #132.Test coverage
internal/tmpl/tmpl_test.go): default used when unset, default ignored when set, empty default, slash in default, separator applied to default, set-to-empty-string uses value not default, multiple defaults, mixed with plain env ref, unset without default still errors, misspelled non-env key still errorse2e/scenarios/env-vars.yaml): default used when unset, default ignored when set, empty default, slash in default, separator applied to defaultenvOrto always return the fallback, confirmed the "default ignored when set" test failed, restoredTest plan
go test ./...— 531 passedgo vet ./...— cleangofmt -l .— cleango run e2e/run.go— 247 passed, 0 failedwt infooutput updated