2018-12-18 02:08:53 +01:00
|
|
|
#!/usr/bin/env bash
|
2017-03-22 21:18:48 +01:00
|
|
|
|
2021-09-01 00:15:31 +02:00
|
|
|
# Lint all commit messages that are newer than upstream/main if running
|
2020-04-28 20:26:58 +02:00
|
|
|
# locally or the commits in the push or PR if in CircleCI.
|
2017-04-22 21:36:52 +02:00
|
|
|
|
2017-03-22 21:18:48 +01:00
|
|
|
# The rules can be found in /.gitlint
|
|
|
|
|
2021-05-06 09:45:34 +02:00
|
|
|
repository="zulip/zulip"
|
|
|
|
|
2020-04-26 19:16:36 +02:00
|
|
|
if [[ "
|
2020-02-04 13:48:17 +01:00
|
|
|
$(git remote -v)
|
|
|
|
" =~ '
|
2021-05-06 09:45:34 +02:00
|
|
|
'([^[:space:]]*)[[:space:]]*(https://github\.com/|ssh://git@github\.com/|git@github\.com:)"$repository"(\.git|/)?\ \(fetch\)'
|
2020-02-04 13:48:17 +01:00
|
|
|
' ]]; then
|
2022-07-22 02:50:32 +02:00
|
|
|
remote=${BASH_REMATCH[1]}
|
2017-04-22 21:36:52 +02:00
|
|
|
else
|
2022-07-22 02:50:32 +02:00
|
|
|
remote=upstream
|
2017-03-22 21:18:48 +01:00
|
|
|
fi
|
|
|
|
|
2022-07-22 02:50:32 +02:00
|
|
|
upstream_commits=$(git rev-parse "refs/remotes/$remote/main" --glob="refs/remotes/$remote/*.x")
|
|
|
|
mapfile -t upstream_commits <<<"$upstream_commits"
|
|
|
|
base=$(git merge-base HEAD "${upstream_commits[@]}")
|
|
|
|
|
|
|
|
commits=$(git rev-list --count "$base..HEAD")
|
2018-03-02 20:49:46 +01:00
|
|
|
if [ "$commits" -gt 0 ]; then
|
|
|
|
# Only run gitlint with non-empty commit lists, to avoid a printed
|
|
|
|
# warning.
|
2022-07-22 02:50:32 +02:00
|
|
|
gitlint --commits "$base..HEAD"
|
2018-03-02 20:49:46 +01:00
|
|
|
fi
|