xtask: install-hooks checks the hook it says it installed #635

Open
qnjk wants to merge 1 commit from qnjk/Darner:hooks-executable into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: cargo xtask install-hooks runs git config core.hooksPath .githooks, checks only the exit status, and then prints hooks installed: commits now run \cargo xtask policy --staged` (xtask/src/main.rs:37-45). But the hook it points at is tracked as mode **100644** (git ls-files -s .githooks/pre-commit→100644 …), and git looks a hook up with access(X_OK)`: on a POSIX clone git prints "The '.githooks/pre-commit' hook was ignored because it's not set as executable" and runs nothing, so the only automated enforcement of the repository's first rule — nothing from the game is ever committed — is absent while the command reports it in place. Git for Windows runs hooks without the execute bit, which is why this looked correct from here.

  • This change fixes both halves of that one defect:

    • .githooks/pre-commit is recorded with the executable bit (git update-index --chmod=+x), so the commit carries mode change 100644 => 100755 and a clone checks it out executable;
    • the command derives its claim from the hook's mode: a new pure installed(mode: Option<u32>) -> Result<String> bails, naming the remedy, when there is a mode with no execute bit; returns the existing success line when there is one; and on Windows (no execute bit to read) prints the success line plus "its mode was not checked — a POSIX clone ignores .githooks/pre-commit unless it is executable".

How it was tested

  • Tested revision: 71e9390 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p xtask — 11 passed, 0 failed (the new tests for installed are among them).
    • cargo clippy --locked -p xtask --all-targets -- -D warnings passes.
    • git show --summary HEAD shows mode change 100644 => 100755 .githooks/pre-commit and no content change to the hook.
    • Fail-before, with only the old command body restored: the tests for the mode-aware claim fail (installed(None) no longer carries the warning; installed(Some(0o644)) returns Ok instead of the error naming the remedy), which is exactly the state that made the command lie.
  • Changes a default: no. On Windows the command still installs the hooks and still succeeds; what changes is that the success line now says what was not checked, and on POSIX a hook that cannot run is an error instead of a false claim.
  • A/B result: not applicable — no default change and no speed claim. The observable claim is the command's output and the hook's file mode.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3: cargo test --locked -p xtask is green (11 passed). The whole-workspace run is not green on this machine for the pre-existing darner-gpu reasons (#224, #150), which this does not touch.
    • cargo xtask policy: passes.
  • Gameplay, when relevant: not applicable — this is the repo's own tooling.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none, though the observable behaviour depends on the host (POSIX needs the execute bit; Git for Windows does not).
  • Coverage gaps: the POSIX path cannot be exercised on this Windows machine; the mode-aware decision function is tested, but the actual access(X_OK) behaviour of a POSIX clone is reasoned from git's documented behaviour, not observed here. The hook's content is unchanged.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not applicable: this is the repository's git tooling; nothing about a run changes.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: passes).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. No open pull request changes xtask/src/main.rs or .githooks/pre-commit (checked against the file list of all 189 open pull requests), and no open or closed issue mentions install-hooks or a hook that is not executable.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `cargo xtask install-hooks` runs `git config core.hooksPath .githooks`, checks only the exit status, and then prints `hooks installed: commits now run \`cargo xtask policy --staged\`` (`xtask/src/main.rs:37-45`). But the hook it points at is tracked as mode **`100644`** (`git ls-files -s .githooks/pre-commit` → `100644 …`), and git looks a hook up with `access(X_OK)`: on a POSIX clone git prints "The '.githooks/pre-commit' hook was ignored because it's not set as executable" and runs nothing, so the only automated enforcement of the repository's first rule — nothing from the game is ever committed — is absent while the command reports it in place. Git for Windows runs hooks without the execute bit, which is why this looked correct from here. - This change fixes both halves of that one defect: - `.githooks/pre-commit` is recorded with the executable bit (`git update-index --chmod=+x`), so the commit carries `mode change 100644 => 100755` and a clone checks it out executable; - the command derives its claim from the hook's mode: a new pure `installed(mode: Option<u32>) -> Result<String>` bails, naming the remedy, when there is a mode with no execute bit; returns the existing success line when there is one; and on Windows (no execute bit to read) prints the success line **plus** "its mode was not checked — a POSIX clone ignores `.githooks/pre-commit` unless it is executable". ## How it was tested - Tested revision: `71e9390` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p xtask` — 11 passed, 0 failed (the new tests for `installed` are among them). - `cargo clippy --locked -p xtask --all-targets -- -D warnings` passes. - `git show --summary HEAD` shows `mode change 100644 => 100755 .githooks/pre-commit` and no content change to the hook. - Fail-before, with only the old command body restored: the tests for the mode-aware claim fail (`installed(None)` no longer carries the warning; `installed(Some(0o644))` returns `Ok` instead of the error naming the remedy), which is exactly the state that made the command lie. - Changes a default: no. On Windows the command still installs the hooks and still succeeds; what changes is that the success line now says what was not checked, and on POSIX a hook that cannot run is an error instead of a false claim. - A/B result: not applicable — no default change and no speed claim. The observable claim is the command's output and the hook's file mode. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3: `cargo test --locked -p xtask` is green (11 passed). The whole-workspace run is not green on this machine for the pre-existing `darner-gpu` reasons (#224, #150), which this does not touch. - `cargo xtask policy`: passes. - Gameplay, when relevant: not applicable — this is the repo's own tooling. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none, though the observable behaviour depends on the host (POSIX needs the execute bit; Git for Windows does not). - Coverage gaps: the POSIX path cannot be exercised on this Windows machine; the mode-aware decision function is tested, but the actual `access(X_OK)` behaviour of a POSIX clone is reasoned from git's documented behaviour, not observed here. The hook's content is unchanged. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not applicable: this is the repository's git tooling; nothing about a run changes. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: passes). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. No open pull request changes `xtask/src/main.rs` or `.githooks/pre-commit` (checked against the file list of all 189 open pull requests), and no open or closed issue mentions `install-hooks` or a hook that is not executable. - Replaces or overlaps: none found
`cargo xtask install-hooks` ran `git config core.hooksPath .githooks`, checked
only the exit status, and printed "hooks installed: commits now run `cargo
xtask policy --staged`". But `.githooks/pre-commit` was tracked as mode 100644,
and git looks a hook up with `access(X_OK)`: on a POSIX clone it says "The
'.githooks/pre-commit' hook was ignored because it's not set as executable"
and runs nothing, so the only automated enforcement of rule 1 (AGENTS.md,
docs/asset-policy.md) was absent while the command reported it in place. Git
for Windows runs hooks without an execute bit, which is why the discrepancy
could not be seen here.

The hook is tracked as 100755 now, so a clone checks it out executable. The
command also stopped asserting the claim: `installed()` is a pure function of
the hook's mode that refuses, naming the remedy (`git update-index --chmod=+x`
and `git checkout --`), when no execute bit is set at all, and says the mode
was not checked on Windows, which keeps none. A mode with some execute bit is
left to the OS: it evaluates the caller's class and this process cannot know
whether it is the owner.

The test pins all three answers without git. The mode itself is read only on
unix, through `std::os::unix::fs::PermissionsExt`, so the Windows branch of
`hook_mode` is the one this machine compiles and runs.
TrustNo1 changed title from [pr-fix] xtask: install-hooks checks the hook it says it installed to xtask: install-hooks checks the hook it says it installed 2026-12-06 03:25:49 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'hooks-executable:qnjk-hooks-executable'
git switch 'qnjk-hooks-executable'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'qnjk-hooks-executable'
git switch 'qnjk-hooks-executable'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-hooks-executable'
git switch 'qnjk-hooks-executable'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-hooks-executable'
git switch 'Main'
git merge --squash 'qnjk-hooks-executable'
git switch 'Main'
git merge --ff-only 'qnjk-hooks-executable'
git switch 'Main'
git merge 'qnjk-hooks-executable'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!635
No description provided.