From 534f505b77500c6f9bc2a7577d5d0dd2843dbaa0 Mon Sep 17 00:00:00 2001 From: Song Fangzhen Date: Wed, 23 Jun 2021 08:51:34 +0000 Subject: [PATCH] Update format of `git cl split` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change updates the output format of `git cl split` when `description_file` has no footers. Bug: 1215852 Change-Id: I69764885337ec31134f2b5e2d861930e0bc8cd2d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2936161 Reviewed-by: Jochen Eisinger Reviewed-by: François Doray Commit-Queue: Fangzhen Song --- split_cl.py | 2 +- tests/split_cl_test.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 tests/split_cl_test.py diff --git a/split_cl.py b/split_cl.py index 9c0bc77ce..f742360b3 100644 --- a/split_cl.py +++ b/split_cl.py @@ -60,7 +60,7 @@ def AddUploadedByGitClSplitToDescription(description): """ split_footers = git_footers.split_footers(description) lines = split_footers[0] - if not lines[-1] or lines[-1].isspace(): + if lines[-1] and not lines[-1].isspace(): lines = lines + [''] lines = lines + ['This CL was uploaded by git cl split.'] if split_footers[1]: diff --git a/tests/split_cl_test.py b/tests/split_cl_test.py new file mode 100755 index 000000000..083ba6083 --- /dev/null +++ b/tests/split_cl_test.py @@ -0,0 +1,37 @@ +#!/usr/bin/env vpython3 +"""Tests for split_cl.""" + +import os +import sys +import unittest + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import split_cl + + +class SplitClTest(unittest.TestCase): + _description = """Convert use of X to Y in $directory + + + +""" + + _footers = 'Bug: 12345' + + def testAddUploadedByGitClSplitToDescription(self): + added_line = 'This CL was uploaded by git cl split.' + + # Description without footers + self.assertEqual( + split_cl.AddUploadedByGitClSplitToDescription(self._description), + self._description + added_line) + # Description with footers + self.assertEqual( + split_cl.AddUploadedByGitClSplitToDescription(self._description + + self._footers), + self._description + added_line + '\n\n' + self._footers) + + +if __name__ == '__main__': + unittest.main()