File tree Expand file tree Collapse file tree 8 files changed +53
-0
lines changed
gix-revision/tests/fixtures Expand file tree Collapse file tree 8 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -359,6 +359,14 @@ jobs:
359359 - name : gix-pack with all features (including wasm)
360360 run : cd gix-pack && cargo build --all-features --target "$TARGET"
361361
362+ check-mode :
363+ runs-on : ubuntu-latest
364+
365+ steps :
366+ - uses : actions/checkout@v4
367+ - name : Find scripts with mode/shebang mismatch
368+ run : etc/check-mode.sh
369+
362370 check-packetline :
363371 strategy :
364372 fail-fast : false
@@ -441,6 +449,7 @@ jobs:
441449 - test-32bit-cross
442450 - lint
443451 - cargo-deny
452+ - check-mode
444453 - check-packetline
445454 - check-blocking
446455
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ set -eu -o pipefail
4+
5+ # Go to the worktree's root. (Even if the dir name ends in a newline.)
6+ root_padded=" $( git rev-parse --show-toplevel && echo -n .) "
7+ root=" ${root_padded% $' \n .' } "
8+ cd -- " $root "
9+
10+ symbolic_shebang=" $( printf ' #!' | od -An -ta) "
11+ status=0
12+
13+ function check () {
14+ local mode=" $1 " oid=" $2 " path=" $3 " symbolic_magic
15+
16+ # Extract the first two bytes (or less if shorter) and put in symbolic form.
17+ symbolic_magic=" $( git cat-file blob " $oid " | od -N2 -An -ta) "
18+
19+ # Check for inconsistency between the mode and whether `#!` is present.
20+ if [ " $mode " = 100644 ] && [ " $symbolic_magic " = " $symbolic_shebang " ]; then
21+ printf ' mode -x but has shebang: %q\n' " $path "
22+ elif [ " $mode " = 100755 ] && [ " $symbolic_magic " != " $symbolic_shebang " ]; then
23+ printf ' mode +x but no shebang: %q\n' " $path "
24+ else
25+ return 0
26+ fi
27+
28+ status=1
29+ }
30+
31+ # Check regular files named with a `.sh` suffix.
32+ while read -rd ' ' mode oid _stage_number path; do
33+ case " $mode " in
34+ 100644 | 100755)
35+ check " $mode " " $oid " " $path "
36+ ;;
37+ esac
38+ done < <( git ls-files -sz -- ' *.sh' )
39+
40+ exit " $status "
Original file line number Diff line number Diff line change @@ -255,6 +255,10 @@ fmt:
255255find-yanked :
256256 cargo install --debug --locked --no-default-features --features max-pure --path .
257257
258+ # Find shell scripts whose +x/-x bits and magic bytes (e.g. `#!`) disagree
259+ check-mode :
260+ ./ etc/ check-mode.sh
261+
258262# Delete gix-packetline-blocking/src and regenerate from gix-packetline/src
259263copy-packetline :
260264 ./ etc/ copy-packetline.sh
You can’t perform that action at this time.
0 commit comments