# ── vcs-commit : Git/JJ commit metadata wrappers ─────────────────────────────
assert_ok "vcs-commit parses as POSIX shell" sh -n "$DOTFILES/bin/vcs-commit"
assert_ok "git-commit wrapper parses" sh -n "$DOTFILES/bin/git-commit"
assert_ok "jj-commit wrapper parses" sh -n "$DOTFILES/bin/jj-commit"
dry_output=$(VCS_COMMIT_DATE=2026-09-01T20:30:00+01:00 \
VCS_COMMIT_HOST=test-host "$DOTFILES/bin/git-commit" --add --push --dry-run \
"feat: test metadata")
assert_contains "dry run includes ISO commit date" "$dry_output" "Commit-Date: 2026-09-01T20:30:00+01:00"
assert_contains "dry run includes commit host" "$dry_output" "Commit-Host: test-host"
assert_contains "dry run reports add" "$dry_output" "git add -A"
assert_contains "dry run reports push" "$dry_output" "git push"
() {
local work message expected
work=$(mktemp -d)
mkdir -p "$work/git"
git -C "$work/git" init -q
git -C "$work/git" config user.name "Commit Wrapper Test"
git -C "$work/git" config user.email "commit-wrapper@example.invalid"
git -C "$work/git" config commit.gpgsign false
print -r -- "tracked by wrapper" > "$work/git/example.txt"
assert_ok "git-commit stages and commits" env \
VCS_COMMIT_DATE=2026-09-01T20:30:00+01:00 VCS_COMMIT_HOST=test-host \
sh -c 'cd "$1" && "$2" --add "feat: wrapper integration"' sh \
"$work/git" "$DOTFILES/bin/git-commit"
message=$(git -C "$work/git" log -1 --format=%B)
expected=$'feat: wrapper integration\n\nCommit-Date: 2026-09-01T20:30:00+01:00\nCommit-Host: test-host'
assert_eq "Git stores message and metadata trailers" "$expected" "$message"
assert_eq "Git worktree is clean after --add" "" "$(git -C "$work/git" status --porcelain)"
rm -rf -- "$work"
}
if (( $+commands[jj] )); then
() {
local work message expected
work=$(mktemp -d)
mkdir -p "$work/config"
XDG_CONFIG_HOME="$work/config" jj git init --colocate "$work/jj" >/dev/null 2>&1
XDG_CONFIG_HOME="$work/config" jj -R "$work/jj" config set --repo \
user.name '"Commit Wrapper Test"' >/dev/null 2>&1
XDG_CONFIG_HOME="$work/config" jj -R "$work/jj" config set --repo \
user.email '"commit-wrapper@example.invalid"' >/dev/null 2>&1
print -r -- "tracked by JJ" > "$work/jj/example.txt"
assert_ok "jj-commit commits the working copy" env \
XDG_CONFIG_HOME="$work/config" \
VCS_COMMIT_DATE=2026-09-01T20:30:00+01:00 VCS_COMMIT_HOST=test-host \
sh -c 'cd "$1" && "$2" "feat: JJ wrapper integration"' sh \
"$work/jj" "$DOTFILES/bin/jj-commit"
message=$(XDG_CONFIG_HOME="$work/config" jj -R "$work/jj" log -r @- \
--no-graph -T 'description')
expected=$'feat: JJ wrapper integration\n\nCommit-Date: 2026-09-01T20:30:00+01:00\nCommit-Host: test-host'
assert_eq "JJ stores message and metadata trailers" "$expected" "$message"
rm -rf -- "$work"
}
fi
# ── stdin message: one Ctrl-D must finish it, wherever the cursor is ──────────
# Regression guard: reading with plain `cat` needed TWO Ctrl-D presses on a
# half-typed line, because canonical mode delivers the partial line instead of
# EOF. Needs a real pty, hence zpty.
if zmodload zsh/zpty 2>/dev/null; then
() {
local -a cases=(
'one Ctrl-D ends a half-typed line' $'fix: half line\C-d'
'one Ctrl-D ends a completed line' $'fix: whole line\n\C-d'
'blank lines inside the body live' $'fix: subject\n\nbody text\n\C-d'
)
local desc keys chunk out expected
while (( $#cases )); do
desc=$cases[1]; keys=$cases[2]; shift 2 cases
zpty vcs_stdin "VCS_COMMIT_DATE=2026-09-01T20:30:00+01:00 \
VCS_COMMIT_HOST=test-host $DOTFILES/bin/jj-commit --dry-run"
zpty -w -n vcs_stdin "$keys"
out=""; chunk=""
while zpty -r vcs_stdin chunk; do out+=$chunk; done
out+=$chunk
zpty -d vcs_stdin 2>/dev/null
assert_contains "stdin: $desc" "$out" "Commit-Host: test-host"
done
# Exactly one blank line before the trailers, however the message was ended.
zpty vcs_stdin "VCS_COMMIT_DATE=2026-09-01T20:30:00+01:00 \
VCS_COMMIT_HOST=test-host $DOTFILES/bin/jj-commit --dry-run"
zpty -w -n vcs_stdin $'fix: trailing newline\n\C-d'
out=""; chunk=""
while zpty -r vcs_stdin chunk; do out+=$chunk; done
out+=$chunk
zpty -d vcs_stdin 2>/dev/null
assert_contains "stdin: closing Enter leaves no extra blank line" \
"${out//$'\r'/}" $'fix: trailing newline\n\nCommit-Date:'
}
fi
# Piped stdin keeps working (no terminal semantics involved).
() {
local out
out=$(printf '%s\n' 'fix: piped subject' '' 'piped body' | \
VCS_COMMIT_DATE=2026-09-01T20:30:00+01:00 VCS_COMMIT_HOST=test-host \
"$DOTFILES/bin/jj-commit" --dry-run)
assert_contains "piped stdin still commits the whole message" "$out" $'fix: piped subject\n\npiped body'
}