Files
zulip/tools/commit-message-lint
Anders Kaseorg fa558de6d8 commit-message-lint: Detect the upstream remote name.
My upstream remote is named origin, so commit-message-lint was always
complaining at me.  Detect the right remote name from the output of
`git remote -v`.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-04 13:57:51 -08:00

27 lines
771 B
Bash
Executable File

#!/usr/bin/env bash
# Lint all commit messages that are newer than upstream/master if running
# locally or the commits in the push or PR if in Travis CI.
# The rules can be found in /.gitlint
if [ "$TRAVIS" ]; then
# Work around https://github.com/travis-ci/travis-ci/issues/4596
range="${TRAVIS_COMMIT_RANGE/.../..}"
elif [[ "
$(git remote -v)
" =~ '
'([^[:space:]]*)[[:space:]]*(https://github\.com/|ssh://git@github\.com/|git@github\.com:)zulip/zulip(\.git|/)?\ \(fetch\)'
' ]]; then
range="${BASH_REMATCH[1]}/master..HEAD"
else
range="upstream/master..HEAD"
fi
commits=$(git log "$range" | wc -l)
if [ "$commits" -gt 0 ]; then
# Only run gitlint with non-empty commit lists, to avoid a printed
# warning.
gitlint --commits "$range"
fi