Skip to content

Support shebang executable checks outside Git repositories - #1285

Closed
Chrisbryan17 wants to merge 1 commit into
pre-commit:mainfrom
Chrisbryan17:fix/shebang-executable-outside-git
Closed

Chrisbryan17 wants to merge 1 commit into
pre-commit:mainfrom
Chrisbryan17:fix/shebang-executable-outside-git

Conversation

@Chrisbryan17

Copy link
Copy Markdown

Closes #749.

Problem

The check-shebang-scripts-are-executable hook unconditionally uses Git's index, so it fails when invoked on files outside a Git worktree.

Change

  • Preserve Git-index executable bits inside working trees.
  • Fall back to filesystem executable permissions on POSIX when outside a Git worktree.
  • Preserve unrelated Git errors and avoid assuming Unix executable semantics on Windows.
  • Add regression coverage for missing Git metadata, permission combinations, and error paths.

Testing

  • Affected tests: 12 passed.
  • Complete tests directory: 407 passed, 13 skipped, 2 xfailed (Windows, Python 3.13, third-party pytest plugin autoload disabled).
  • git diff --check: passed.
  • POSIX filesystem behavior was simulated with monkeypatches; it was not tested on a native POSIX host.

@pre-commit pre-commit locked as spam and limited conversation to collaborators Oct 21, 2026
@asottile asottile closed this Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

check-shebang-scripts-are-executable Assumes Git Repo

2 participants