Skip to content

Commit fdf85a8

Browse files
committed
feat(hooks): update post-checkout and post-specify hooks to accept additional arguments
1 parent e229215 commit fdf85a8

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

hooks/README.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ Copy-Item .specify/hooks/prepare-feature-num.ps1.sample .specify/hooks/prepare-f
4949
### `post-checkout` - Post-Checkout Hook
5050
- **When**: After branch creation and checkout (matches Git's `post-checkout`)
5151
- **Purpose**: Setup tasks after branch creation but before spec writing
52-
- **Arguments**: `$1` = feature description
53-
- **Environment**: `BRANCH_NAME`, `SPEC_FILE`, `FEATURE_NUM` are available
52+
- **Arguments**:
53+
- `$1` = feature description
54+
- `$2` = feature number
55+
- `$3` = branch name
56+
- `$4` = spec file path
57+
- **Environment**: `BRANCH_NAME`, `SPEC_FILE`, `FEATURE_NUM` also available
5458
- **Exit codes**: Non-zero exit codes show warnings but don't stop execution
5559

5660
**Example uses:**
@@ -62,8 +66,12 @@ Copy-Item .specify/hooks/prepare-feature-num.ps1.sample .specify/hooks/prepare-f
6266
### `post-specify` - Post-Specification Hook
6367
- **When**: After spec file is completely written (true post-specify)
6468
- **Purpose**: Final integration tasks and notifications
65-
- **Arguments**: `$1` = feature description
66-
- **Environment**: `BRANCH_NAME`, `SPEC_FILE`, `FEATURE_NUM` are available
69+
- **Arguments**:
70+
- `$1` = feature description
71+
- `$2` = feature number
72+
- `$3` = branch name
73+
- `$4` = spec file path
74+
- **Environment**: `BRANCH_NAME`, `SPEC_FILE`, `FEATURE_NUM` also available
6775
- **Exit codes**: Non-zero exit codes show warnings but don't stop execution
6876

6977
**Example uses:**
@@ -123,10 +131,13 @@ Write-Output $issueNumber
123131
#!/bin/bash
124132
# .specify/hooks/post-checkout
125133
FEATURE_DESC="$1"
134+
FEATURE_NUM="$2"
135+
BRANCH_NAME="$3"
136+
SPEC_FILE="$4"
126137
# Create additional project directories
127138
mkdir -p "docs/$BRANCH_NAME"
128139
# Set up branch-specific configuration
129-
echo "Branch $BRANCH_NAME created for: $FEATURE_DESC" > "docs/$BRANCH_NAME/info.txt"
140+
echo "Branch $BRANCH_NAME (#$FEATURE_NUM) created for: $FEATURE_DESC" > "docs/$BRANCH_NAME/info.txt"
130141
```
131142

132143
### Post-Specification Notification
@@ -136,8 +147,11 @@ echo "Branch $BRANCH_NAME created for: $FEATURE_DESC" > "docs/$BRANCH_NAME/info.
136147
#!/bin/bash
137148
# .specify/hooks/post-specify
138149
FEATURE_DESC="$1"
150+
FEATURE_NUM="$2"
151+
BRANCH_NAME="$3"
152+
SPEC_FILE="$4"
139153
# Create completion issue
140-
gh issue create --title "Spec Complete: $FEATURE_DESC" --body "Specification ready for review: $SPEC_FILE"
154+
gh issue create --title "Spec Complete #$FEATURE_NUM: $FEATURE_DESC" --body "Specification ready for review: $SPEC_FILE on branch $BRANCH_NAME"
141155
# Send notification
142156
echo "Specification $FEATURE_NUM completed: $SPEC_FILE" | mail -s "Spec Ready" [email protected]
143157
```
@@ -150,9 +164,9 @@ echo "Specification $FEATURE_NUM completed: $SPEC_FILE" | mail -s "Spec Ready" t
150164
- **Cross-platform**: System automatically detects and uses appropriate hook format.
151165

152166
### Hook Execution
153-
- Hooks are called with the feature description as the first argument
154-
- The `feature-num` hook should output only the number to stdout
155-
- The `post-specify` hook has access to environment variables set by the create script
167+
- Hooks are called with multiple arguments: feature description, feature number, branch name, spec file path
168+
- The `prepare-feature-num` hook should output only the number to stdout
169+
- All hooks have access to environment variables (BRANCH_NAME, SPEC_FILE, FEATURE_NUM) in addition to explicit arguments
156170
- Failed hooks generate warnings but don't stop the specification process
157171
- Non-existent or non-executable hook files are safely ignored
158172

templates/commands/specify.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Given the feature description provided as an argument, do this:
1717
3. Run the script `{SCRIPT}` from repo root (with optional --feature-num parameter) and parse its JSON output for BRANCH_NAME, SPEC_FILE, and FEATURE_NUM. All file paths must be absolute.
1818
4. Export environment variables: `export BRANCH_NAME SPEC_FILE FEATURE_NUM` (Unix) or `$env:BRANCH_NAME = ...; $env:SPEC_FILE = ...; $env:FEATURE_NUM = ...` (Windows)
1919
5. Run post-checkout hook if available (ignore errors):
20-
- Windows: Try `.specify/hooks/post-checkout.ps1 "{ARGS}"` then `.specify/hooks/post-checkout "{ARGS}"`
21-
- Unix/Linux: Try `.specify/hooks/post-checkout "{ARGS}"`
20+
- Windows: Try `.specify/hooks/post-checkout.ps1 "{ARGS}" "$FEATURE_NUM" "$BRANCH_NAME" "$SPEC_FILE"` then `.specify/hooks/post-checkout "{ARGS}" "$FEATURE_NUM" "$BRANCH_NAME" "$SPEC_FILE"`
21+
- Unix/Linux: Try `.specify/hooks/post-checkout "{ARGS}" "$FEATURE_NUM" "$BRANCH_NAME" "$SPEC_FILE"`
2222
6. Load `templates/spec-template.md` to understand required sections.
2323
7. Write the specification to SPEC_FILE using the template structure, replacing placeholders with concrete details derived from the feature description (arguments) while preserving section order and headings.
2424
8. Run post-specify hook if available (ignore errors):
25-
- Windows: Try `.specify/hooks/post-specify.ps1 "{ARGS}"` then `.specify/hooks/post-specify "{ARGS}"`
26-
- Unix/Linux: Try `.specify/hooks/post-specify "{ARGS}"`
25+
- Windows: Try `.specify/hooks/post-specify.ps1 "{ARGS}" "$FEATURE_NUM" "$BRANCH_NAME" "$SPEC_FILE"` then `.specify/hooks/post-specify "{ARGS}" "$FEATURE_NUM" "$BRANCH_NAME" "$SPEC_FILE"`
26+
- Unix/Linux: Try `.specify/hooks/post-specify "{ARGS}" "$FEATURE_NUM" "$BRANCH_NAME" "$SPEC_FILE"`
2727
9. Report completion with branch name, spec file path, and readiness for the next phase.
2828

2929
Note: The script creates and checks out the new branch and initializes the spec file before writing. Hooks follow Git-style naming: pre-specify for validation, prepare-feature-num for custom numbering, post-checkout after branch creation, and post-specify after spec completion.

0 commit comments

Comments
 (0)