[1/2,pre-commit] Reject symlinks in check-file-mode
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
Commit Message
In a recent commit I introduced two symlinks.
After reading a bit more about it, I realized that this can be problematic on
platforms without proper support for it [1].
Which is probably also the reason why there aren't any symlinks in the repo
other than those two.
Eliminate the symlinks, and extend check-file-mode to reject symlinks.
While we're at it, move the existing check into a function, and improve
comments and error message a bit.
[1] https://gitforwindows.org/symbolic-links.html
---
.pre-commit-config.yaml | 4 ++
gdb/contrib/check-file-mode.sh | 77 +++++++++++++++++++++++-----------
gdbserver/.shellcheckrc | 4 +-
gdbsupport/.shellcheckrc | 4 +-
4 files changed, 63 insertions(+), 26 deletions(-)
mode change 120000 => 100644 gdbserver/.shellcheckrc
mode change 120000 => 100644 gdbsupport/.shellcheckrc
@@ -151,6 +151,10 @@ repos:
language: unsupported_script
entry: gdb/contrib/check-file-mode.sh
files: *gdb_files
+ # With the default types == [file], because types and types_or are
+ # and-ed, no symlinks will be selected, so we use types == [] instead.
+ types: []
+ types_or: [file, symlink]
- id: &id5 shellcheck
name: *id5
files: '^(gdb|gdbsupport|gdbserver)/'
@@ -17,30 +17,59 @@
set -e
set -o pipefail
-no_exec_files=()
-for f in "$@"; do
- case $f in
- */*.py \
- | */*.sh \
- | */configure \
- | gdb/gstack-1.in \
- | gdb/gcore-1.in \
- | gdb/po/gdbtext \
- | gdb/make-init-c \
- | gdb/testsuite/lib/notty-wrap )
- continue
- ;;
- *)
- no_exec_files=("${no_exec_files[@]}" "$f")
- ;;
- esac
-done
+# Flag files that are executable, but not meant to be executable.
+check_exec ()
+{
+ no_exec_files=()
+ for f in "$@"; do
+ case $f in
+ */*.py \
+ | */*.sh )
+ # Shell script or python.
+ continue
+ ;;
+ gdb/po/gdbtext \
+ | gdb/make-init-c \
+ | gdb/testsuite/lib/notty-wrap )
+ # Shell script without .sh extension.
+ continue
+ ;;
+ */configure \
+ | gdb/gstack-1.in \
+ | gdb/gcore-1.in )
+ # Used to generate shell script.
+ continue
+ ;;
+ *)
+ no_exec_files=("${no_exec_files[@]}" "$f")
+ ;;
+ esac
+ done
-if [ ${#no_exec_files[@]} -eq 0 ]; then
- exit 0
-fi
+ if [ ${#no_exec_files[@]} -eq 0 ]; then
+ return
+ fi
-# Flag files that are executable, but not meant to be executable.
+ if ! git ls-files --stage -- "${no_exec_files[@]}" \
+ | (! grep '^100755 '); then
+ echo "Found executable mode (100755) on file without .sh or .py"
+ echo "Please fix or add to exception list in $0"
+ exit 1
+ fi
+}
+
+# Flag symlinks. Symlinks are support by git, but can be problematic on
+# platforms without proper support for it [1].
+# [1] https://gitforwindows.org/symbolic-links.html
+check_symlinks ()
+{
+ if ! git ls-files --stage -- "$@" \
+ | (! grep '^120000 '); then
+ echo "Found symlink mode (120000)"
+ echo "Please replace by copy"
+ exit 1
+ fi
+}
-git ls-files --stage -- "${no_exec_files[@]}" \
- | (! grep '^100755 ')
+check_exec "$@"
+check_symlinks "$@"
deleted file mode 120000
@@ -1 +0,0 @@
-../gdb/.shellcheckrc
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,3 @@
+# SC2002 was disabled by default in 0.11.0. Turn it on for
+# compatibility with 0.10.0.
+enable=useless-use-of-cat
deleted file mode 120000
@@ -1 +0,0 @@
-../gdb/.shellcheckrc
\ No newline at end of file
new file mode 100644
@@ -0,0 +1,3 @@
+# SC2002 was disabled by default in 0.11.0. Turn it on for
+# compatibility with 0.10.0.
+enable=useless-use-of-cat