From cc29098042868c6b833efa40c09762f8c4be326b Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Mon, 21 Sep 2020 20:40:18 +0000 Subject: [PATCH] Strip trailing empty lines when getting footers Take the following git change description (Note: added ~ to avoid having these lines be parsed as tags): ``` ~Test ~ ~Bug: something ~Change-Id: Something ``` Sometimes(?) `git log --pretty=format:%B%n ..` returns: ``` ~Test ~ ~Bug: something ~Change-Id: Something ``` The trailing empty line trips split_footers() up, making it return an empty footer. This change removes trailing empty lines before processing them. Bug: 1130601 Change-Id: Ib8d6c37ad6817a47a744245d1a2455ac9af6c469 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2422378 Commit-Queue: Dirk Pranke Reviewed-by: Dirk Pranke Auto-Submit: Shahbaz Youssefi --- git_footers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/git_footers.py b/git_footers.py index b882ac3a0..05d1cbef3 100755 --- a/git_footers.py +++ b/git_footers.py @@ -66,6 +66,12 @@ def split_footers(message): last paragraph are malformed. """ message_lines = list(message.splitlines()) + + # First, remove trailing empty lines from the change to get to the footer + while len(message_lines) > 0 and (message_lines[-1] == '' + or message_lines[-1].isspace()): + message_lines.pop() + footer_lines = [] maybe_footer_lines = [] for line in reversed(message_lines):