-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1708 from EliahKagan/run-ci/mode
Check for executable bits that disagree with shebangs
- Loading branch information
Showing
8 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
# Go to the worktree's root. (Even if the dir name ends in a newline.) | ||
root_padded="$(git rev-parse --show-toplevel && echo -n .)" | ||
root="${root_padded%$'\n.'}" | ||
cd -- "$root" | ||
|
||
symbolic_shebang="$(printf '#!' | od -An -ta)" | ||
status=0 | ||
|
||
function check () { | ||
local mode="$1" oid="$2" path="$3" symbolic_magic | ||
|
||
# Extract the first two bytes (or less if shorter) and put in symbolic form. | ||
symbolic_magic="$(git cat-file blob "$oid" | od -N2 -An -ta)" | ||
|
||
# Check for inconsistency between the mode and whether `#!` is present. | ||
if [ "$mode" = 100644 ] && [ "$symbolic_magic" = "$symbolic_shebang" ]; then | ||
printf 'mode -x but has shebang: %q\n' "$path" | ||
elif [ "$mode" = 100755 ] && [ "$symbolic_magic" != "$symbolic_shebang" ]; then | ||
printf 'mode +x but no shebang: %q\n' "$path" | ||
else | ||
return 0 | ||
fi | ||
|
||
status=1 | ||
} | ||
|
||
# Check regular files named with a `.sh` suffix. | ||
while read -rd '' mode oid _stage_number path; do | ||
case "$mode" in | ||
100644 | 100755) | ||
check "$mode" "$oid" "$path" | ||
;; | ||
esac | ||
done < <(git ls-files -sz -- '*.sh') | ||
|
||
exit "$status" |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters