From 77a800d7294d29ded899af9685c65babb3a62821 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Fri, 24 Jan 2025 14:15:15 -0800 Subject: [PATCH] Print branch name when running presubmits This implements the proposed solution B in https://crbug.com/380877175#comment5 and will help distinguish presubmit results when working with stacked changes. Bug: 380877175 Change-Id: I7f0807f7ce03109288976069c57c28488d6cadfd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6196130 Reviewed-by: Yiwei Zhang Commit-Queue: Gavin Mak --- presubmit_support.py | 12 ++++++++---- tests/presubmit_unittest.py | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index 00a29a2f0..0feba2c86 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -1922,10 +1922,14 @@ def DoPresubmitChecks(change, 1 if presubmit checks failed or 0 otherwise. """ with setup_environ({'PYTHONDONTWRITEBYTECODE': '1'}): - if committing: - sys.stdout.write('Running presubmit commit checks ...\n') - else: - sys.stdout.write('Running presubmit upload checks ...\n') + running_msg = 'Running presubmit ' + running_msg += 'commit ' if committing else 'upload ' + running_msg += 'checks ' + if branch := scm.GIT.GetBranch(change.RepositoryRoot()): + running_msg += f'on branch {branch} ' + running_msg += '...\n' + sys.stdout.write(running_msg) + start_time = time_time() presubmit_files = ListRelevantPresubmitFiles( change.AbsoluteLocalPaths() + change.AbsoluteLocalSubmodules(), diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 9694b0c8d..1c4db0a56 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -194,6 +194,7 @@ index fe3de7b..54ae6e1 100755 mock.patch('presubmit_support.warn').start() mock.patch('random.randint').start() mock.patch('scm.GIT.GenerateDiff').start() + mock.patch('scm.GIT.GetBranch', lambda x: None).start() mock.patch('scm.determine_scm').start() mock.patch('subprocess2.Popen').start() mock.patch('sys.stderr', StringIO()).start()