mirror of
https://github.com/apache/nuttx.git
synced 2026-05-10 07:18:49 +08:00
tools/checkpatch.sh: Enhance stdin support for patch checking
- Added functionality to read patch content from stdin when using the '--stdin' option with the '-p' flag. - Updated usage instructions to clarify the new stdin option for patch checks. - Improved error handling for unsupported combinations of options. Signed-off-by: Arjav Patel <arjav1528@gmail.com>
This commit is contained in:
+20
-3
@@ -61,6 +61,7 @@ usage() {
|
||||
echo "-b Enforce breaking change format when checking commit message (requires -m -g; use when PR has breaking change label)"
|
||||
echo "-g <commit list>"
|
||||
echo " Use --stdin as the only argument with -m -g to read commit message from stdin (message-only check, no patch/diff)."
|
||||
echo " Use --stdin with -p to read patch content from stdin."
|
||||
echo "-f <file list>"
|
||||
echo "-x format supported files (only .py, requires: pip install black)"
|
||||
echo "- read standard input mainly used by git pre-commit hook as below:"
|
||||
@@ -442,9 +443,25 @@ while [ ! -z "$1" ]; do
|
||||
done
|
||||
|
||||
for arg in $@; do
|
||||
if [ "$arg" = "--stdin" ] && [ "$check" = "check_commit" ]; then
|
||||
msg=$(cat)
|
||||
check_msg <<< "$msg"
|
||||
if [ "$arg" = "--stdin" ]; then
|
||||
case "$check" in
|
||||
check_commit)
|
||||
msg=$(cat)
|
||||
check_msg <<< "$msg"
|
||||
;;
|
||||
check_patch)
|
||||
tmp=$(mktemp)
|
||||
trap "rm -f $tmp" EXIT
|
||||
cat > "$tmp"
|
||||
check_patch "$tmp"
|
||||
rm -f "$tmp"
|
||||
trap - EXIT
|
||||
;;
|
||||
check_file|format_file)
|
||||
echo "❌ --stdin is only supported with -g (commit message) or -p (patch)"
|
||||
fail=1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
$check $arg
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user