Skip to content

feat(branch): branch hook variables - #151

Merged
Everduin94 merged 2 commits into
mainfrom
everduin94/feat/branch-hook-variables
Aug 14, 2026
Merged

Everduin94 merged 2 commits into
mainfrom
everduin94/feat/branch-hook-variables

Conversation

@Everduin94

Copy link
Copy Markdown
Owner

Added ability to use variables, for example {{TICKET}}, inside of hooks. This allows you to access branch state in hooks / scripts.

Added ability to use variables, for example {{TICKET}}, inside of hooks.
This allows you to access branch state in hooks / scripts.
Copilot AI lite review requested due to automatic review settings August 14, 2026 20:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BranchHooks runner to select pre/post hook sets (branch vs worktree), render templates, and execute/log hooks.
  • Updates BranchConfirmPrompt and 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 thread src/branch-hooks.ts
Comment on lines +58 to +63
try {
execSync(command, { stdio: "inherit" });
} catch (err) {
p.log.error(`${error_message}${command}\n${err}`);
throw err;
}
Comment thread readme.md
Comment on lines +274 to +275
// - Variables: {{USER}}, {{TYPE}}, {{SCOPE}}, {{DESCRIPTION}}, {{TICKET}}, {{BRANCH-VERSION}}, {{CHECKOUT}}
// - Values are shell-quoted automatically: {{TICKET}} --> 'JIRA-123'
@Everduin94
Everduin94 merged commit 53ff09a into main Aug 14, 2026
4 checks passed
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))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.25.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants