validate-dco 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. source "$(dirname "$BASH_SOURCE")/.validate"
  3. adds=$(validate_diff --numstat | awk '{ s += $1 } END { print s }')
  4. dels=$(validate_diff --numstat | awk '{ s += $2 } END { print s }')
  5. notDocs="$(validate_diff --numstat | awk '$3 !~ /^docs\// { print $3 }')"
  6. : ${adds:=0}
  7. : ${dels:=0}
  8. if [ $adds -eq 0 -a $dels -eq 0 ]; then
  9. echo '0 adds, 0 deletions; nothing to validate! :)'
  10. elif [ -z "$notDocs" -a $adds -le 1 -a $dels -le 1 ]; then
  11. echo 'Congratulations! DCO small-patch-exception material!'
  12. else
  13. dcoPrefix='Docker-DCO-1.1-Signed-off-by:'
  14. dcoRegex="^$dcoPrefix ([^<]+) <([^<>@]+@[^<>]+)> \\(github: (\S+)\\)$"
  15. commits=( $(validate_log --format='format:%H%n') )
  16. badCommits=()
  17. for commit in "${commits[@]}"; do
  18. if [ -z "$(git log -1 --format='format:' --name-status "$commit")" ]; then
  19. # no content (ie, Merge commit, etc)
  20. continue
  21. fi
  22. if ! git log -1 --format='format:%B' "$commit" | grep -qE "$dcoRegex"; then
  23. badCommits+=( "$commit" )
  24. fi
  25. done
  26. if [ ${#badCommits[@]} -eq 0 ]; then
  27. echo "Congratulations! All commits are properly signed with the DCO!"
  28. else
  29. {
  30. echo "These commits do not have a proper '$dcoPrefix' marker:"
  31. for commit in "${badCommits[@]}"; do
  32. echo " - $commit"
  33. done
  34. echo
  35. echo 'Please amend each commit to include a properly formatted DCO marker.'
  36. echo
  37. echo 'Visit the following URL for information about the Docker DCO:'
  38. echo ' https://github.com/dotcloud/docker/blob/master/CONTRIBUTING.md#sign-your-work'
  39. echo
  40. } >&2
  41. false
  42. fi
  43. fi