From ae85cac5a99952b2499ce5ebec9d4fe2a540bb40 Mon Sep 17 00:00:00 2001 From: Thomas Desveaux Date: Sat, 8 Jun 2024 14:57:05 +0200 Subject: [PATCH 1/3] gitpoller: fix _get_commit_files for merge commits --- master/buildbot/changes/gitpoller.py | 2 +- .../test/unit/changes/test_gitpoller.py | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/master/buildbot/changes/gitpoller.py b/master/buildbot/changes/gitpoller.py index 794309853fcb..d726eb29d3dc 100644 --- a/master/buildbot/changes/gitpoller.py +++ b/master/buildbot/changes/gitpoller.py @@ -432,7 +432,7 @@ def process(git_output): return d def _get_commit_files(self, rev): - args = ['--name-only', '--no-walk', r'--format=%n', rev, '--'] + args = ['--name-only', '--no-walk', r'--format=%n', '-m', '--first-parent', rev, '--'] d = self._dovccmd('log', args, path=self.workdir) def decode_file(file): diff --git a/master/buildbot/test/unit/changes/test_gitpoller.py b/master/buildbot/test/unit/changes/test_gitpoller.py index 0cbc7574ad2c..4e09c19a8d6e 100644 --- a/master/buildbot/test/unit/changes/test_gitpoller.py +++ b/master/buildbot/test/unit/changes/test_gitpoller.py @@ -183,7 +183,16 @@ def test_get_commit_files(self): filesRes = ['file1', 'file2', 'file_octal', 'file space'] return self._perform_git_output_test( self.poller._get_commit_files, - ['log', '--name-only', '--no-walk', '--format=%n', self.dummyRevStr, '--'], + [ + 'log', + '--name-only', + '--no-walk', + '--format=%n', + '-m', + '--first-parent', + self.dummyRevStr, + '--', + ], filesBytes, filesRes, emptyRaisesException=False, @@ -194,7 +203,16 @@ def test_get_commit_files_with_space_in_changed_files(self): filesStr = bytes2unicode(filesBytes) return self._perform_git_output_test( self.poller._get_commit_files, - ['log', '--name-only', '--no-walk', '--format=%n', self.dummyRevStr, '--'], + [ + 'log', + '--name-only', + '--no-walk', + '--format=%n', + '-m', + '--first-parent', + self.dummyRevStr, + '--', + ], filesBytes, [l for l in filesStr.splitlines() if l.strip()], emptyRaisesException=False, @@ -2680,7 +2698,7 @@ async def test_poll_from_last(self): 'codebase': None, 'comments': "Merge branch 'feature/1'", 'committer': 'test user ', - 'files': [], + 'files': ['README.md'], 'project': '', 'properties': {}, 'repository': self.repo_url, From 5f973962e5af2f85980ecec65ca82f65b17c9af6 Mon Sep 17 00:00:00 2001 From: Thomas Desveaux Date: Sat, 8 Jun 2024 15:06:31 +0200 Subject: [PATCH 2/3] gitpoller: fix _process_changes to only list commit from tracked branch On non-fast-forward merges, only the merge commit should be listed. --- master/buildbot/changes/gitpoller.py | 2 +- .../test/unit/changes/test_gitpoller.py | 35 ++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/master/buildbot/changes/gitpoller.py b/master/buildbot/changes/gitpoller.py index d726eb29d3dc..49ae3244b965 100644 --- a/master/buildbot/changes/gitpoller.py +++ b/master/buildbot/changes/gitpoller.py @@ -489,7 +489,7 @@ def _process_changes(self, newRev, branch): # get the change list revListArgs = ( - ['--ignore-missing'] + ['--ignore-missing', '--first-parent'] + ['--format=%H', f'{newRev}'] + ['^' + rev for rev in sorted(self.lastRev.values())] + ['--'] diff --git a/master/buildbot/test/unit/changes/test_gitpoller.py b/master/buildbot/test/unit/changes/test_gitpoller.py index 4e09c19a8d6e..f6b2143ec8ab 100644 --- a/master/buildbot/test/unit/changes/test_gitpoller.py +++ b/master/buildbot/test/unit/changes/test_gitpoller.py @@ -405,6 +405,7 @@ def test_poll_failLog(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^fa3ae8ed68e664d4db24798611b352e3c6509930', @@ -488,6 +489,7 @@ def test_poll_nothingNew(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^4423cdbcbb89c14e50dd5f4152415afd686c5241', @@ -598,6 +600,7 @@ def test_poll_multipleBranches(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^bf0b01df6d00ae8d1ffa0b2e2acbe642a6cd35d5', @@ -622,6 +625,7 @@ def test_poll_multipleBranches(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '9118f4ab71963d23d02d4bdc54876ac8bf05acf2', '^4423cdbcbb89c14e50dd5f4152415afd686c5241', @@ -759,6 +763,7 @@ def test_poll_multipleBranches_buildPushesWithNoCommits_default(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^4423cdbcbb89c14e50dd5f4152415afd686c5241', @@ -811,6 +816,7 @@ def test_poll_multipleBranches_buildPushesWithNoCommits_true(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^4423cdbcbb89c14e50dd5f4152415afd686c5241', @@ -910,6 +916,7 @@ def test_poll_multipleBranches_buildPushesWithNoCommits_true_fast_forward(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^0ba9d553b7217ab4bbad89ad56dc0332c7d57a8c', @@ -1013,6 +1020,7 @@ def test_poll_multipleBranches_buildPushesWithNoCommits_true_not_tip(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^0ba9d553b7217ab4bbad89ad56dc0332c7d57a8c', @@ -1108,6 +1116,7 @@ def test_poll_allBranches_single(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^fa3ae8ed68e664d4db24798611b352e3c6509930', @@ -1218,6 +1227,7 @@ def test_poll_noChanges(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^4423cdbcbb89c14e50dd5f4152415afd686c5241', @@ -1265,6 +1275,7 @@ def test_poll_allBranches_multiple(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^bf0b01df6d00ae8d1ffa0b2e2acbe642a6cd35d5', @@ -1289,6 +1300,7 @@ def test_poll_allBranches_multiple(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '9118f4ab71963d23d02d4bdc54876ac8bf05acf2', '^4423cdbcbb89c14e50dd5f4152415afd686c5241', @@ -1396,6 +1408,7 @@ def test_poll_callableFilteredBranches(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^bf0b01df6d00ae8d1ffa0b2e2acbe642a6cd35d5', @@ -1507,6 +1520,7 @@ def test_poll_branchFilter(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '9118f4ab71963d23d02d4bdc54876ac8bf05acf2', '^bf0b01df6d00ae8d1ffa0b2e2acbe642a6cd35d5', @@ -1613,6 +1627,7 @@ def test_poll_old(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^fa3ae8ed68e664d4db24798611b352e3c6509930', @@ -1727,6 +1742,7 @@ def test_poll_callableCategory(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '4423cdbcbb89c14e50dd5f4152415afd686c5241', '^fa3ae8ed68e664d4db24798611b352e3c6509930', @@ -1851,6 +1867,7 @@ def test_startService_loadLastRev(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', 'fa3ae8ed68e664d4db24798611b352e3c6509930', '^fa3ae8ed68e664d4db24798611b352e3c6509930', @@ -1961,6 +1978,7 @@ async def test_poll_found_head(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '737b94eca1ddde3dd4a0040b25c8a25fe973fe09', '^4423cdbcbb89c14e50dd5f4152415afd686c5241', @@ -2011,6 +2029,7 @@ async def test_poll_found_head_not_found(self): 'git', 'log', '--ignore-missing', + '--first-parent', '--format=%H', '737b94eca1ddde3dd4a0040b25c8a25fe973fe09', '^4423cdbcbb89c14e50dd5f4152415afd686c5241', @@ -2675,22 +2694,6 @@ async def test_poll_from_last(self): 'src': 'git', 'when_timestamp': 1717855320, }, - { - 'author': 'test user ', - 'branch': 'main', - 'category': None, - 'codebase': None, - 'comments': 'Feature 1', - 'committer': 'test user ', - 'files': ['README.md'], - 'project': '', - 'properties': {}, - 'repository': self.repo_url, - 'revision': self.FEATURE_1_SHA, - 'revlink': '', - 'src': 'git', - 'when_timestamp': 1717855380, - }, { 'author': 'test user ', 'branch': 'main', From 3150d227de565f533ae40feb54aa83af550a9661 Mon Sep 17 00:00:00 2001 From: Thomas Desveaux Date: Sun, 7 Jul 2024 19:54:08 +0200 Subject: [PATCH 3/3] Add newsfragment --- newsfragments/git-poller-on-merge-commits.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/git-poller-on-merge-commits.bugfix diff --git a/newsfragments/git-poller-on-merge-commits.bugfix b/newsfragments/git-poller-on-merge-commits.bugfix new file mode 100644 index 000000000000..d536d3bac7a9 --- /dev/null +++ b/newsfragments/git-poller-on-merge-commits.bugfix @@ -0,0 +1 @@ +Fix ``GitPoller`` merge commit processing. ``GitPoller`` now correctly list merge commit files. (:issue:`7494`) \ No newline at end of file