X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=check_commits;h=9011cb3c11d99db1af6c594d233f31f9b5adc786;hb=HEAD;hp=5d7d0602ed57d1a74f6dfcfca1d7ed23f039eb6d;hpb=c017b7c1aecca8f853090a32eaeb5f114cffecbd;p=next-scripts diff --git a/check_commits b/check_commits index 5d7d060..9011cb3 100755 --- a/check_commits +++ b/check_commits @@ -1,21 +1,26 @@ #!/bin/bash if [ "$#" -lt 1 ]; then - printf "Usage: %s \n", "$0" 1>&2 + printf 'Usage: %s \n' "$0" 1>&2 exit 1 fi commits=$(git rev-list --no-merges "$@") if [ -z "$commits" ]; then - printf "No commits\n" + printf 'No commits\n' exit 0 fi -author_missing= -committer_missing= +"$(realpath "$(dirname "$0")")/check_fixes" "$@" + +declare -a author_missing committer_missing print_commits() { + if [ "$#" -eq 1 ]; then + return + fi + local t="$1" shift @@ -23,38 +28,56 @@ print_commits() s= is='is' its='its' - [ "$#" -gt 1 ] && { + if [ "$#" -gt 1 ]; then s='s' is='are' its='their' - } - printf "Commit%s\n\n" "$s" + fi + printf 'Commit%s\n\n' "$s" git log --no-walk --pretty='format: %h ("%s")' "$@" - printf "\n%s missing a Signed-off-by from %s %s%s.\n" "$is" "$its" "$t" "$s" - printf "\n" + printf '\n%s missing a Signed-off-by from %s %s%s.\n\n' \ + "$is" "$its" "$t" "$s" +} + +check_unexpected_files() +{ + local files + + readarray files < <(git diff-tree -r --diff-filter=A --name-only --no-commit-id "$1" '*.rej' '*.orig') + if [ "${#files[@]}" -eq 0 ]; then + return + fi + + s= + this='this' + if [ "${#files[@]}" -gt 1 ]; then + s='s' + this='these' + fi + + printf 'Commit\n\n' + git log --no-walk --pretty='format: %h ("%s")' "$1" + printf '\nadded %s unexpected file%s:\n\n' "$this" "$s" + printf ' %s\n' "${files[@]}" } for c in $commits; do ae=$(git log -1 --format='<%ae>%n<%aE>%n %an %n %aN ' "$c" | sort -u) ce=$(git log -1 --format='<%ce>%n<%cE>%n %cn %n %cN ' "$c" | sort -u) - msg=$(git log -1 --format='%b' "$c") - sob=$(echo "$msg" | sed -En 's/^\s*Signed-off-by:?\s*/ /ip') - - am=false - cm=false - grep -i -F -q "$ae" <<<"$sob" || - am=true - grep -i -F -q "$ce" <<<"$sob" || - cm=true - "$am" && author_missing+=" $c" - "$cm" && committer_missing+=" $c" + sob=$(git log -1 --format='%b' "$c" | + sed -En 's/^\s*Signed-off-by:?\s*/ /ip') + + if ! grep -i -F -q "$ae" <<<"$sob"; then + author_missing+=("$c") + fi + if ! grep -i -F -q "$ce" <<<"$sob"; then + committer_missing+=("$c") + fi + + check_unexpected_files "$c" done -if [ "$author_missing" ]; then - print_commits "author" $author_missing -fi -if [ "$committer_missing" ]; then - print_commits "committer" $committer_missing -fi +print_commits 'author' "${author_missing[@]}" +print_commits 'committer' "${committer_missing[@]}" exec gitk "$@"