From 7212f08e9c78cd7d9f3cfae6b9212279708c47e1 Mon Sep 17 00:00:00 2001 From: Christoph Blecker Date: Thu, 25 Jun 2026 22:14:14 -0700 Subject: [PATCH] feat(git): override branch.autosetupmerge=false via CLAUDE_ENV_FILE Use GIT_CONFIG_COUNT/KEY/VALUE environment variables written to CLAUDE_ENV_FILE to set branch.autosetupmerge=false for the session. Deferred expansion ensures additivity with other plugins or pre-existing environment entries. Assisted-by: Claude:claude-opus-4-6 --- git/.claude-plugin/plugin.json | 2 +- git/CLAUDE.md | 22 +++++++++++++++++++++- git/README.md | 10 ++++++++++ git/scripts/git-instructions.sh | 11 +++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/git/.claude-plugin/plugin.json b/git/.claude-plugin/plugin.json index 3ad0564..1bc9154 100644 --- a/git/.claude-plugin/plugin.json +++ b/git/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "git", - "version": "1.4.0", + "version": "1.5.0", "description": "Dynamic git instructions via SessionStart hook with mainline detection, conventional commits, fork handling, and safety guardrails", "author": { "name": "cblecker", diff --git a/git/CLAUDE.md b/git/CLAUDE.md index deca1e1..1a9aed5 100644 --- a/git/CLAUDE.md +++ b/git/CLAUDE.md @@ -8,11 +8,12 @@ are needed. ```text SessionStart → git-instructions.sh → stdout (instructions injected as context) - ↓ + ↓ → CLAUDE_ENV_FILE (git config overrides) 1. Detect mainline branch 2. Detect conventional commits 3. Detect fork setup 4. Output instructions with detected values + 5. Write git config env overrides (if CLAUDE_ENV_FILE available) ``` ### Prerequisite @@ -62,6 +63,25 @@ instructions and warn the user if both built-in and plugin instructions are present. This keeps detection logic out of the script and lets Claude handle it contextually. +### Git config overrides via environment + +Rather than modifying git config files (which the safety protocol forbids), the +script writes `GIT_CONFIG_COUNT`/`GIT_CONFIG_KEY_n`/`GIT_CONFIG_VALUE_n` +environment variables to `CLAUDE_ENV_FILE`. These override git settings for the +session without persisting to disk. + +The entries use deferred expansion via a single-quoted heredoc: literal +`${GIT_CONFIG_COUNT:-0}` references are written to the file and expand at +source-time. This makes the approach additive — if another plugin or the parent +environment has already set entries, our entries append at the next available +index rather than overwriting. + +Current overrides: + +| Setting | Value | Reason | +|---------|-------|--------| +| `branch.autosetupmerge` | `false` | Prevents unintended tracking setup when creating branches | + ### Differences from built-in instructions - `main/master` replaced with detected mainline branch name diff --git a/git/README.md b/git/README.md index 970ee38..661e345 100644 --- a/git/README.md +++ b/git/README.md @@ -25,6 +25,7 @@ At session start, the plugin runs a detection script that: 1. **Detects your mainline branch** (via `origin HEAD`, falls back to `main`/`master`) 2. **Detects conventional commits** (commitlint config or commit history analysis) 3. **Detects fork setup** (checks for `upstream` remote) +4. **Sets git config overrides** via `CLAUDE_ENV_FILE` environment variables Then injects tailored git instructions covering: @@ -53,6 +54,15 @@ The plugin auto-detects repository conventions at session start. | Conventional commits | commitlint config files, commit history pattern matching | | Fork setup | Presence of `upstream` remote | +### Git Config Overrides + +When `CLAUDE_ENV_FILE` is available, the plugin writes environment variables to +override git settings for the session (without modifying git config files): + +| Setting | Value | Reason | +|---------|-------|--------| +| `branch.autosetupmerge` | `false` | Prevents unintended tracking when creating branches | + ## Testing Validate the plugin: diff --git a/git/scripts/git-instructions.sh b/git/scripts/git-instructions.sh index ce52b74..4d0e7e2 100755 --- a/git/scripts/git-instructions.sh +++ b/git/scripts/git-instructions.sh @@ -274,3 +274,14 @@ ${BRANCH_NAMING} - Check \`git branch\` before creating to avoid duplicates EOF + +############################################################################### +# Environment: Git config overrides via CLAUDE_ENV_FILE +############################################################################### +if [[ -n "${CLAUDE_ENV_FILE:-}" ]]; then + cat >> "${CLAUDE_ENV_FILE}" <<'ENVEOF' +export GIT_CONFIG_KEY_${GIT_CONFIG_COUNT:-0}=branch.autosetupmerge +export GIT_CONFIG_VALUE_${GIT_CONFIG_COUNT:-0}=false +export GIT_CONFIG_COUNT=$(( ${GIT_CONFIG_COUNT:-0} + 1 )) +ENVEOF +fi