* feat(extensions): port git extension scripts to Python Ports git-common, initialize-repo, auto-commit, and create-new-feature-branch to extensions/git/scripts/python/, mirroring the bash/PowerShell twins. Parity tests run each bash script and its Python twin in identical projects and compare output, exit codes, and resulting git state. Fixes #3282 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: match bash error message for whitespace-only descriptions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Handle unreadable git-config.yml and assert stderr parity An unreadable config file raised OSError with a full traceback from _parse_auto_commit_config. Treat it like a missing config: auto-commit stays disabled. Covered by a chmod-000 test (skipped on non-POSIX and as root). _assert_parity now also compares stderr so warning or usage-text regressions between the bash and Python twins fail the suite. All existing parity tests pass with the stricter assertion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(extensions/git): pass script path to core.get_repo_root for cwd-outside-repo callers Without script_file, core.get_repo_root() falls back to Path.cwd() when SPECIFY_INIT_DIR is unset and no .specify root is found upward — the bash twin instead falls back to the script's install location (.specify/scripts/...). Pass script_file so both twins resolve the same repo_root; TypeError fallback keeps older cores working. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test: exercise SPECIFY_INIT_DIR from outside the project Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(extensions/git): handle UnicodeDecodeError and USER/USERNAME fallback - Catch (OSError, UnicodeDecodeError) when reading git-config.yml in create_new_feature_branch.py, initialize_repo.py, and auto_commit.py so invalid UTF-8 config falls back to defaults instead of crashing with a traceback. - Fall back to USERNAME (then "unknown") when USER is unset when deriving the branch author token, matching the PowerShell twin's Windows-friendly fallback chain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(extensions/git): platform-aware persist hint and stronger SPECIFY_INIT_DIR test - Add a shared _persist_hint() helper in create_new_feature_branch.py and use it for both the JSON-mode stderr hint and the human-readable stdout hint, so there is a single place emitting the SPECIFY_FEATURE persistence guidance. On Windows (os.name == "nt") it prints PowerShell $env:VAR = "..." syntax; elsewhere it keeps the existing POSIX export VAR=... syntax (parity with the bash twin). - Rework test_specify_init_dir_resolves_target_project so SPECIFY_INIT_DIR is the only thing that can produce the observed result: the script now runs from a separate host_proj (no existing specs, so script/cwd-based discovery would yield 001) while SPECIFY_INIT_DIR points at a different target_proj that already has an existing spec (007-existing, so the override must yield 008). The old version pointed SPECIFY_INIT_DIR at the same project the script was installed in, so it passed even if the env var were ignored. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(extensions): tolerate missing Git executable Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(extensions): quote PowerShell persist hint Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(git): match bash persist hint escaping Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(git): ignore unterminated config record Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test(git): handle Windows persist hint parity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(init): install Python shared scripts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test(git): normalize Windows persistence hints Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Git Branching Workflow Extension
Git repository initialization, feature branch creation, numbering (sequential/timestamp), validation, remote detection, and auto-commit for Spec Kit.
Overview
This extension provides Git operations as an optional, self-contained module. It manages:
- Repository initialization with configurable commit messages
- Feature branch creation with sequential (
001-feature-name) or timestamp (20260319-143022-feature-name) numbering and optional templates for branch namespaces - Branch validation to ensure branches follow naming conventions
- Git remote detection for GitHub integration (e.g., issue creation)
- Auto-commit after core commands (configurable per-command with custom messages)
Commands
| Command | Description |
|---|---|
speckit.git.initialize |
Initialize a Git repository with a configurable commit message |
speckit.git.feature |
Create a feature branch with sequential or timestamp numbering |
speckit.git.validate |
Validate current branch follows feature branch naming conventions |
speckit.git.remote |
Detect Git remote URL for GitHub integration |
speckit.git.commit |
Auto-commit changes (configurable per-command enable/disable and messages) |
Hooks
| Event | Command | Optional | Description |
|---|---|---|---|
before_constitution |
speckit.git.initialize |
No | Init git repo before constitution |
before_specify |
speckit.git.feature |
No | Create feature branch before specification |
before_clarify |
speckit.git.commit |
Yes | Commit outstanding changes before clarification |
before_plan |
speckit.git.commit |
Yes | Commit outstanding changes before planning |
before_tasks |
speckit.git.commit |
Yes | Commit outstanding changes before task generation |
before_implement |
speckit.git.commit |
Yes | Commit outstanding changes before implementation |
before_checklist |
speckit.git.commit |
Yes | Commit outstanding changes before checklist |
before_analyze |
speckit.git.commit |
Yes | Commit outstanding changes before analysis |
before_taskstoissues |
speckit.git.commit |
Yes | Commit outstanding changes before issue sync |
after_constitution |
speckit.git.commit |
Yes | Auto-commit after constitution update |
after_specify |
speckit.git.commit |
Yes | Auto-commit after specification |
after_clarify |
speckit.git.commit |
Yes | Auto-commit after clarification |
after_plan |
speckit.git.commit |
Yes | Auto-commit after planning |
after_tasks |
speckit.git.commit |
Yes | Auto-commit after task generation |
after_implement |
speckit.git.commit |
Yes | Auto-commit after implementation |
after_checklist |
speckit.git.commit |
Yes | Auto-commit after checklist |
after_analyze |
speckit.git.commit |
Yes | Auto-commit after analysis |
after_taskstoissues |
speckit.git.commit |
Yes | Auto-commit after issue sync |
Configuration
Configuration is stored in .specify/extensions/git/git-config.yml:
# Branch numbering strategy: "sequential" or "timestamp"
branch_numbering: sequential
# Optional branch name template. Leave empty for the default "{number}-{slug}".
# Supported tokens: {author}, {app}, {number}, {slug}; {slug} must not appear
# before {number}, and the final path segment must start with {number}-.
# Example for monorepos: "{author}/{app}/{number}-{slug}"
branch_template: ""
# Optional shorthand namespace. Leave empty to use branch_template/default behavior.
# Example: "features/{app}" expands to "features/{app}/{number}-{slug}"
branch_prefix: ""
# Custom commit message for git init
init_commit_message: "[Spec Kit] Initial commit"
# Auto-commit per command (all disabled by default)
# Example: enable auto-commit after specify
auto_commit:
default: false
after_specify:
enabled: true
message: "[Spec Kit] Add specification"
{author} is derived from Git config and sanitized for branch names. {app} is derived from the Spec Kit init directory name. Custom templates must not put {slug} before {number}, and must put {number}- at the start of the final path segment so generated names remain valid feature branches. For a monorepo project at apps/web/.specify/, a template such as {author}/{app}/{number}-{slug} produces branches like jdoe/web/008-guided-tour.
For simple namespace-only customization, branch_prefix is also accepted as a shorthand and expands to <branch_prefix>/{number}-{slug}.
Installation
# Install the bundled git extension (no network required)
specify extension add git
Disabling
# Disable the git extension (spec creation continues without branching)
specify extension disable git
# Re-enable it
specify extension enable git
Graceful Degradation
When Git is not installed or the directory is not a Git repository:
- Spec directories are still created under
specs/ - Branch creation is skipped with a warning
- Branch validation is skipped with a warning
- Remote detection returns empty results
Scripts
The extension bundles cross-platform scripts:
scripts/bash/create-new-feature-branch.sh— Bash implementation (branch creation only)scripts/bash/git-common.sh— Shared Git utilities (Bash)scripts/powershell/create-new-feature-branch.ps1— PowerShell implementation (branch creation only)scripts/powershell/git-common.ps1— Shared Git utilities (PowerShell)