Skip to content

careful: force-push check fires on a plain git push when a later command in the same line has a +token or -f (e.g. date +%F) #4601

Closed

Description

@TayTaySwizzle

gstack 1.101.0.0 (b702243), careful/bin/check-careful.sh.

What happens

The destructive-command check asks for confirmation ("Destructive: git force-push rewrites remote history") on an ordinary push when the same Bash command contains a + token or -f somewhere else. This command triggered it:

git add .planning/STATE.md && git commit -q -m "docs(state): ..." && git push -q 2>&1 | grep -v "^remote:"; git log --oneline -1; echo "$(date +%F) checkpoint" >> notes.log

Nothing in it force-pushes. The +%F belongs to date.

Cause

Lines 340 to 345 run two independent greps over the whole command string:

if [ -z "$WARN" ] && grep -qE 'git\s+push\s' <<< "$CMD_MEDIUM" 2>/dev/null \
  && grep -qE '(-f\b|--force|(^|[[:space:]])\+[^[:space:]])' <<< "$CMD_MEDIUM" 2>/dev/null; then

The first finds git push, and the second finds +%F from date. The second grep isn't limited to the push's own arguments, so any later +token or -f anywhere in the line counts. That includes date +%F, chmod +x, rm -f, tail -f, and sort -f. Since the check is a PreToolUse hook, it prompts even in bypass-permissions mode.

Expected

Match force flags only among the arguments of the git push itself, stopping at the first ;, &&, ||, |, newline, or redirect. A rough version:

push_args=$(grep -oE 'git\s+push\b[^;&|<>]*' <<< "$CMD_MEDIUM")
grep -qE '(^|\s)(-f|--force(-with-lease)?)(\s|$)|(^|\s)\+[^[:space:]]' <<< "$push_args"

A real git push origin +main, git push -f, or git push --force should still warn.

Activity

  1. TayTaySwizzle commented on Nov 21, 2026

    @TayTaySwizzle
    ContributorAuthor

    A second case from the same check: it also fires on text inside a quoted argument, with no push being run at all. Filing this issue tripped it:

    gh issue create -R garrytan/gstack --title "careful: force-push check fires on a plain git push when a later command in the same line has a +token or -f (e.g. date +%F)" --body-file report.md

    The only git push, +token, and -f here are words in the quoted --title. The commit-message masking (mask-commit-message.awk) only applies to git commit, so quoted arguments to any other command, such as gh issue create --title, gh pr create --body, or echo "...", are matched as if they were commands. Masking every quoted string before the force-push match, or matching only an unquoted git push command word, would cover both cases.

  2. added
    bug
    S3
    on Nov 21, 2026
  3. capy-ai commented on Nov 21, 2026

    @capy-ai
    Contributor

    Thanks for the report and the second case.

    The first case is fixed: since #4513 (55aaa6c, released in v1.102.0.0) the check reads force flags from the push's own arguments only. On main (bd77c8c) your exact command, and git push -q origin feat && chmod +x foo && rm -f bar, pass with no prompt, while git push -f, git push --force and git push origin +feat still ask. You're on 1.101.0.0, so upgrading clears it.

    The second case still reproduces on main: a gh issue create whose quoted title mentions git push and a +token gets the force-push prompt. I'm leaving this open as a low-severity bug for that part. Changes to this check have to keep everything it currently catches, so it won't be a quick one-line change.

  4. capy-ai commented on Nov 22, 2026

    @capy-ai
    Contributor

    Picking up the second case, the quoted text that mentions git push and a +token. Your first case was fixed in v1.102.0.0. A maintainer agent working on the destructive-command check (our tracking thread GSTA-685) will first reproduce it on current main. Changes to this check only ever allow a command when it's a different spelling of one the check already allows, so a fix has to fit that rule. If it reproduces and fits, we'll close this with a link to the change. If it no longer reproduces, we'll close it and say what changed.

  5. capy-ai commented on Nov 22, 2026

    @capy-ai
    Contributor

    Thanks for the second case. Fixed in #4604 (9055979): the quoted --title/--body (-t/-b) of gh issue and gh pr create, comment and edit is now read as text, so your gh issue create --title "... git push ... +token ... -f" command no longer prompts. A command substitution inside double quotes, a later statement, a pipe, echo and bash -c are still checked. The first case was already fixed in v1.102.0.0 (#4513). It ships in the next release.

  6. added a commit that references this issue on Nov 22, 2026
    9055979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S3bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions