From 9c63edc7323abe8131658df7f1497a3509d3d0bf Mon Sep 17 00:00:00 2001 From: Drew Ritter Date: Mon, 23 Mar 2026 13:06:09 -0700 Subject: [PATCH] feat(finishing-a-development-branch): add Step 1.5 environment detection (PRI-823) Detect externally managed worktrees with detached HEAD and emit handoff payload instead of 4-option menu. Includes commit SHA and data loss warning. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../finishing-a-development-branch/SKILL.md | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/skills/finishing-a-development-branch/SKILL.md b/skills/finishing-a-development-branch/SKILL.md index c308b43b..9ea42d2a 100644 --- a/skills/finishing-a-development-branch/SKILL.md +++ b/skills/finishing-a-development-branch/SKILL.md @@ -37,6 +37,50 @@ Stop. Don't proceed to Step 2. **If tests pass:** Continue to Step 2. +### Step 1.5: Detect Environment + +````bash +GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P) +GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P) +BRANCH=$(git branch --show-current) +```` + +**Path A — `GIT_DIR` differs from `GIT_COMMON` AND `BRANCH` is empty (externally managed worktree, detached HEAD):** + +First, ensure all work is staged and committed (`git add` + `git commit`). + +Then present this to the user (do NOT present the 4-option menu): + +``` +Implementation complete. All tests passing. +Current HEAD: + +This workspace is externally managed (detached HEAD). +I cannot create branches, push, or open PRs from here. + +⚠ These commits are on a detached HEAD. If you do not create a branch, +they may be lost when this workspace is cleaned up. + +If your host application provides these controls: +- "Create branch" — to name a branch, then commit/push/PR +- "Hand off to local" — to move changes to your local checkout + +Suggested branch name: +Suggested commit message: +``` + +Branch name: use ticket ID if available (e.g., `pri-823/codex-compat`), otherwise slugify the first 5 words of the plan title, otherwise omit. Avoid sensitive content in branch names. + +Skip to Step 5 (cleanup is a no-op — see guard below). + +**Path B — `GIT_DIR` differs from `GIT_COMMON` AND `BRANCH` exists (externally managed worktree, named branch):** + +Proceed to Step 2 and present the 4-option menu as normal. + +**Path C — `GIT_DIR` equals `GIT_COMMON` (normal environment):** + +Proceed to Step 2 and present the 4-option menu as normal. + ### Step 2: Determine Base Branch ```bash