Skip to content

Commit c789ce2

Browse files
committed
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>
1 parent c0ed2ac commit c789ce2

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

tools/checkpatch.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ usage() {
6161
echo "-b Enforce breaking change format when checking commit message (requires -m -g; use when PR has breaking change label)"
6262
echo "-g <commit list>"
6363
echo " Use --stdin as the only argument with -m -g to read commit message from stdin (message-only check, no patch/diff)."
64+
echo " Use --stdin with -p to read patch content from stdin."
6465
echo "-f <file list>"
6566
echo "-x format supported files (only .py, requires: pip install black)"
6667
echo "- read standard input mainly used by git pre-commit hook as below:"
@@ -442,9 +443,25 @@ while [ ! -z "$1" ]; do
442443
done
443444

444445
for arg in $@; do
445-
if [ "$arg" = "--stdin" ] && [ "$check" = "check_commit" ]; then
446-
msg=$(cat)
447-
check_msg <<< "$msg"
446+
if [ "$arg" = "--stdin" ]; then
447+
case "$check" in
448+
check_commit)
449+
msg=$(cat)
450+
check_msg <<< "$msg"
451+
;;
452+
check_patch)
453+
tmp=$(mktemp)
454+
trap "rm -f $tmp" EXIT
455+
cat > "$tmp"
456+
check_patch "$tmp"
457+
rm -f "$tmp"
458+
trap - EXIT
459+
;;
460+
check_file|format_file)
461+
echo "❌ --stdin is only supported with -g (commit message) or -p (patch)"
462+
fail=1
463+
;;
464+
esac
448465
else
449466
$check $arg
450467
fi

0 commit comments

Comments
 (0)