Skip to content

Read a Bare Push After a Leading cd and Skip Heredoc Text in gh-write-guard #2821

Closed as not planned

Description

@ptr727

Problem

gh-write-guard.py reads a bare git push as "a direct push to 'develop'" in two shapes where nothing pushes to develop.

  1. A push in a later segment after a leading cd. The session's working directory was the base clone, on develop. The command was a leading cd into a linked worktree on a feature branch, whose upstream was its own remote branch, followed by ;-separated segments, the push among them:

    cd ~/repos/worktrees/Example-task && python3 <hub>/scripts/local_review.py record --target develop --expect-digest <d> --findings 0; echo "record=$?"; git push 2>&1 | tail -1

    The shell runs the push in the worktree, since the cd persists across ;, so it targets the feature branch. The guard denied it as a push to develop, apparently reading @{push}/HEAD in the session's own cwd rather than in the directory the leading cd names.

  2. The words git push inside a heredoc body. A command writing an issue body with cat > file <<'EOF' ... EOF, then gh issue create --body-file file, was denied the same way. The heredoc text described shape 1 and contained git push, but the command itself pushed nothing.

Expected

  • A leading cd applies to every later segment of the same command line, whether joined by && or by ;, so the push branch is read in the worktree the cd names.
  • Heredoc body text is data and is not classified as a command.

Workaround

  • For shape 1, push with an explicit refspec (<branch>:refs/heads/<branch>), which the guard read correctly in the same session.
  • For shape 2, write the text with a file tool rather than a heredoc.

Observed while driving a pull request in a downstream repository. The causes are inferred from the guard's behavior and not confirmed against its parser.

Activity

  1. ptr727 commented on Oct 13, 2026

    @ptr727
    OwnerAuthor

    Shape 1 is fixed on main through #2930: #2928, #2931, #2935 and #2939. A bare git push after a plain leading cd (joined by && or ;), or after -C, is read in that directory, and any other cd form, a .. component, an unresolvable or rooted driveless Windows path, or a cd inside a wrapper fails closed. Shape 2, heredoc text naming a push, is deliberately left unfixed. A carve-out for quoted cat/tee heredocs drew a new bypass in each of ten review rounds on #2928 and was removed, so heredoc bodies are scanned as before. The workaround stays the same: write the text with a file tool. This issue now tracks only shape 2. The guard's other pre-existing gaps are on #2936 and #2932.

  2. ptr727 commented on Oct 13, 2026

    @ptr727
    OwnerAuthor

    Closed as won't-fix, per the maintainer. An allow for heredoc data is new bypass surface in a safety hook, as ten review rounds on #2928 showed, and writing the text with a file tool costs little. Shape 1 shipped in 2.0.1013. The guard's remaining gaps are tracked on #2936 and #2932.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions