Repository navigation
feat(branch): branch hook variables - #151
Merged
Merged
Conversation
Added ability to use variables, for example {{TICKET}}, inside of hooks.
This allows you to access branch state in hooks / scripts.
There was a problem hiding this comment.
Pull request overview
Adds support for using branch-derived template variables (e.g., {{TICKET}}) inside configured branch/worktree hook commands, with automatic shell-quoting to reduce command-injection risk. This extends the better-branch workflow hooks so scripts can consume the current branch state reliably.
Changes:
- Introduces a hook-command renderer that substitutes a fixed set of
{{TOKEN}}placeholders and POSIX single-quote escapes substituted values. - Adds a
BranchHooksrunner to select pre/post hook sets (branch vs worktree), render templates, and execute/log hooks. - Updates
BranchConfirmPromptand documentation/tests to use and validate the new templating behavior.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/render-hook-command.ts | Implements hook template substitution + POSIX single-quote escaping. |
| src/utils/render-hook-command.test.ts | Adds comprehensive unit tests for token matching, escaping, and non-matches. |
| src/branch-hooks.ts | New hook orchestration (select, render, run pre/post; dry-run logging). |
| src/prompts/branch-confirm.prompt.ts | Switches pre/post hook execution to BranchHooks. |
| src/prompts/branch-confirm.prompt.test.ts | Expands tests to cover template rendering, ordering, and failure behavior. |
| src/default-config-template.ts | Documents available hook variables and auto-quoting behavior. |
| readme.md | Updates docs/examples for branch/worktree hooks and templating. |
| package-lock.json | Version bump + lockfile dependency changes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+186
to
+187
| // - Variables: {{USER}}, {{TYPE}}, {{SCOPE}}, {{DESCRIPTION}}, {{TICKET}}, {{BRANCH-VERSION}}, {{CHECKOUT}} | ||
| // - Values are shell-quoted automatically: {{TICKET}} --> 'JIRA-123' |
Comment on lines
+58
to
+63
| try { | ||
| execSync(command, { stdio: "inherit" }); | ||
| } catch (err) { | ||
| p.log.error(`${error_message}${command}\n${err}`); | ||
| throw err; | ||
| } |
Comment on lines
+274
to
+275
| // - Variables: {{USER}}, {{TYPE}}, {{SCOPE}}, {{DESCRIPTION}}, {{TICKET}}, {{BRANCH-VERSION}}, {{CHECKOUT}} | ||
| // - Values are shell-quoted automatically: {{TICKET}} --> 'JIRA-123' |
github-actions Bot
pushed a commit
that referenced
this pull request
Aug 14, 2026
# [1.25.0](v1.24.0...v1.25.0) (2026-08-14) ### Features * **branch:** branch hook variables ([#151](#151)) ([53ff09a](53ff09a))
|
🎉 This PR is included in version 1.25.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Added ability to use variables, for example {{TICKET}}, inside of hooks. This allows you to access branch state in hooks / scripts.