Fix errors when the tagging GitHub releases

When the commit description contains "commit ", it will be wrongly identified
as commit hash.  This commit changes to take only lines begins with "commit "
as a fix, since the description is always indented by `git log`.

Copybara uses merge commit for external contributors, this causes that not all
commits contain a Piper ID. Adding `--first-parent` to `git log` so that it
only lists commits that contain a Piper ID.

PiperOrigin-RevId: 338183812
This commit is contained in:
Ting-Yu Wang 2020-10-20 19:28:32 -07:00 committed by gVisor bot
parent 16ba350314
commit 7dc108b41f
1 changed files with 4 additions and 2 deletions

View File

@ -43,7 +43,7 @@ fi
closest_commit() {
while read line; do
if [[ "$line" =~ "commit " ]]; then
if [[ "$line" =~ ^"commit " ]]; then
current_commit="${line#commit }"
continue
elif [[ "$line" =~ "PiperOrigin-RevId: " ]]; then
@ -57,7 +57,9 @@ closest_commit() {
# Is the passed identifier a sha commit?
if ! git show "${target_commit}" &> /dev/null; then
# Extract the commit given a piper ID.
declare -r commit="$(git log | closest_commit "${target_commit}")"
commit="$(set +o pipefail; \
git log --first-parent | closest_commit "${target_commit}")"
declare -r commit
else
declare -r commit="${target_commit}"
fi