The checkpatches.sh script was checking if stdin is a terminal before
honoring the -n flag, causing it to incorrectly attempt to read patches
from stdin when run without a TTY (e.g., in Jenkins/CI pipelines).

Reorder the conditionals to check for the -n flag before checking stdin
state. This ensures the -n flag takes precedence and the script checks
git commits as intended.

Signed-off-by: Ali Alnubani <[email protected]>
---
 devtools/checkpatches.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/devtools/checkpatches.sh b/devtools/checkpatches.sh
index 9fb8fd0a07..0884f24839 100755
--- a/devtools/checkpatches.sh
+++ b/devtools/checkpatches.sh
@@ -558,9 +558,7 @@ if [ -n "$1" ] ; then
        for patch in "$@" ; do
                check "$patch" ''
        done
-elif [ ! -t 0 ] ; then # stdin
-       check '' ''
-else
+elif [ $number -ne 0 ] || [ -t 0 ]; then
        if [ $number -eq 0 ] ; then
                commits=$(git rev-list --reverse $range)
        else
@@ -569,6 +567,8 @@ else
        for commit in $commits ; do
                check '' $commit
        done
+else # stdin
+       check '' ''
 fi
 pass=$(($total - $status))
 $quiet || printf '\n%d/%d valid patch' $pass $total
-- 
2.43.0

Reply via email to