| 1 |
#!/usr/bin/env bash |
| 2 |
# Create a branch name from an issue number and title. |
| 3 |
# Usage: make-issue-branch.sh <issue-number> "<issue-title>" [base-ref] |
| 4 |
# |
| 5 |
# base-ref: optional git ref to branch from (default: current HEAD). |
| 6 |
# Pass an explicit ref such as "origin/chore/add-ai-assistant" when |
| 7 |
# running inside a worktree or after a git fetch to avoid inheriting |
| 8 |
# unexpected commits from a different branch. |
| 9 |
set -euo pipefail |
| 10 |
|
| 11 |
# Required arguments. |
| 12 |
ISSUE_NUMBER="${1:?issue number required}" |
| 13 |
TITLE="${2:?issue title required}" |
| 14 |
BASE_REF="${3:-HEAD}" |
| 15 |
|
| 16 |
# Build a short, URL-safe slug from the title (first 4 words max). |
| 17 |
SLUG="$(printf '%s' "$TITLE" \ |
| 18 |
| tr '[:upper:]' '[:lower:]' \ |
| 19 |
| sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//' \ |
| 20 |
| cut -d- -f1-4)" |
| 21 |
|
| 22 |
# Branch naming convention: fix/<issue>-<slug> |
| 23 |
BRANCH="fix/${ISSUE_NUMBER}-${SLUG}" |
| 24 |
|
| 25 |
# Create and switch to the branch from the explicit base. |
| 26 |
git checkout -b "$BRANCH" "$BASE_REF" |
| 27 |
echo "$BRANCH" |
| 28 |
|