Skip to content

Commit e332518

Browse files
feat: gracefully skip SSH commit signing when agent is unavailable
Add ssh_signing_available() check so commits proceed unsigned when the 1Password / SSH agent socket is not reachable, instead of failing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 379fa6e commit e332518

7 files changed

Lines changed: 62 additions & 22 deletions

File tree

scripts/doctor.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ if [ -f .env ]; then
3838
if [ -n "${SSH_PUBLIC_KEY:-}" ]; then
3939
git config --global gpg.format ssh
4040
git config --global user.signingkey "key::${SSH_PUBLIC_KEY}"
41-
git config --global commit.gpgsign true
41+
if ssh_signing_available; then
42+
git config --global commit.gpgsign true
43+
else
44+
git config --global commit.gpgsign false
45+
fi
4246
fi
4347
if [ -n "${GITHUB_TOKEN:-}" ] && command -v gh &> /dev/null; then
4448
gh auth setup-git 2>/dev/null || true
@@ -59,9 +63,13 @@ else
5963
fi
6064

6165
# --- SSH commit signing ---
62-
SIGNING=$(git config --global commit.gpgsign 2>/dev/null || echo "")
63-
if [ "$SIGNING" = "true" ]; then
64-
log_success "SSH commit signing enabled."
66+
SIGNING_KEY=$(git config --global user.signingkey 2>/dev/null || echo "")
67+
if [ -n "$SIGNING_KEY" ]; then
68+
if ssh_signing_available; then
69+
log_success "SSH commit signing enabled (1Password / SSH agent detected)."
70+
else
71+
log_info "SSH signing key configured but agent not available — signing disabled."
72+
fi
6573
else
6674
log_info "SSH commit signing not configured (optional)."
6775
fi

scripts/setup-env.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ fi
9696
if [ -n "$SSH_PUBLIC_KEY" ]; then
9797
git config --global gpg.format ssh
9898
git config --global user.signingkey "key::${SSH_PUBLIC_KEY}"
99-
git config --global commit.gpgsign true
99+
if ssh_signing_available; then
100+
git config --global commit.gpgsign true
101+
log_success "SSH commit signing enabled (agent available)."
102+
else
103+
git config --global commit.gpgsign false
104+
log_warn "SSH key saved but agent not available — signing disabled. Commits will proceed unsigned."
105+
fi
100106
fi
101107

102108
if [ -n "$GEMINI_API_KEY" ]; then

scripts/utils.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ read_env() {
8282
fi
8383
}
8484

85+
# Check if the SSH agent is available for commit signing.
86+
# Returns 0 if SSH_AUTH_SOCK is set and the agent responds.
87+
ssh_signing_available() {
88+
[ -n "${SSH_AUTH_SOCK:-}" ] && [ -S "${SSH_AUTH_SOCK}" ] && ssh-add -L &>/dev/null
89+
}
90+
8591
# Ensure we are at the repository root
8692
ensure_root() {
8793
local script_dir

templates/README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,18 @@ make setup
104104

105105
Start developing! Use the universal `Makefile` targets:
106106

107-
| Command | Purpose |
108-
| ----------------- | -------------------------------- |
109-
| `make help` | Show all available targets |
110-
| `make setup` | Install deps & configure hooks |
111-
| `make doctor` | Check environment health |
112-
| `make new-adr` | Scaffold a new architecture record|
113-
| `make ai-context` | Bundle project context for AI |
114-
| `make dev` | Start the development server |
115-
| `make test` | Run the test suite |
116-
| `make build` | Create a production build |
117-
| `make lint` | Run code formatting & linting |
118-
| `make clean` | Remove build artifacts |
107+
| Command | Purpose |
108+
| ----------------- | ---------------------------------- |
109+
| `make help` | Show all available targets |
110+
| `make setup` | Install deps & configure hooks |
111+
| `make doctor` | Check environment health |
112+
| `make new-adr` | Scaffold a new architecture record |
113+
| `make ai-context` | Bundle project context for AI |
114+
| `make dev` | Start the development server |
115+
| `make test` | Run the test suite |
116+
| `make build` | Create a production build |
117+
| `make lint` | Run code formatting & linting |
118+
| `make clean` | Remove build artifacts |
119119

120120
---
121121

templates/scripts/doctor.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ if [ -f .env ]; then
3838
if [ -n "${SSH_PUBLIC_KEY:-}" ]; then
3939
git config --global gpg.format ssh
4040
git config --global user.signingkey "key::${SSH_PUBLIC_KEY}"
41-
git config --global commit.gpgsign true
41+
if ssh_signing_available; then
42+
git config --global commit.gpgsign true
43+
else
44+
git config --global commit.gpgsign false
45+
fi
4246
fi
4347
if [ -n "${GITHUB_TOKEN:-}" ] && command -v gh &> /dev/null; then
4448
gh auth setup-git 2>/dev/null || true
@@ -59,9 +63,13 @@ else
5963
fi
6064

6165
# --- SSH commit signing ---
62-
SIGNING=$(git config --global commit.gpgsign 2>/dev/null || echo "")
63-
if [ "$SIGNING" = "true" ]; then
64-
log_success "SSH commit signing enabled."
66+
SIGNING_KEY=$(git config --global user.signingkey 2>/dev/null || echo "")
67+
if [ -n "$SIGNING_KEY" ]; then
68+
if ssh_signing_available; then
69+
log_success "SSH commit signing enabled (1Password / SSH agent detected)."
70+
else
71+
log_info "SSH signing key configured but agent not available — signing disabled."
72+
fi
6573
else
6674
log_info "SSH commit signing not configured (optional)."
6775
fi

templates/scripts/setup-env.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ fi
9898
if [ -n "$SSH_PUBLIC_KEY" ]; then
9999
git config --global gpg.format ssh
100100
git config --global user.signingkey "key::${SSH_PUBLIC_KEY}"
101-
git config --global commit.gpgsign true
101+
if ssh_signing_available; then
102+
git config --global commit.gpgsign true
103+
log_success "SSH commit signing enabled (agent available)."
104+
else
105+
git config --global commit.gpgsign false
106+
log_warn "SSH key saved but agent not available — signing disabled. Commits will proceed unsigned."
107+
fi
102108
fi
103109

104110
if [ -n "$GEMINI_API_KEY" ]; then

templates/scripts/utils.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ read_env() {
8282
fi
8383
}
8484

85+
# Check if the SSH agent is available for commit signing.
86+
# Returns 0 if SSH_AUTH_SOCK is set and the agent responds.
87+
ssh_signing_available() {
88+
[ -n "${SSH_AUTH_SOCK:-}" ] && [ -S "${SSH_AUTH_SOCK}" ] && ssh-add -L &>/dev/null
89+
}
90+
8591
# Ensure we are at the repository root
8692
ensure_root() {
8793
local script_dir

0 commit comments

Comments
 (0)