@@ -136,8 +136,13 @@ def test_run_git_cliff_no_config(mock_find_config):
136136
137137
138138@patch ("openwisp_utils.releaser.changelog.find_cliff_config" , return_value = "path" )
139- @patch ("subprocess.run" , side_effect = FileNotFoundError )
139+ @patch ("subprocess.run" )
140140def test_run_git_cliff_file_not_found (mock_run , mock_find_config ):
141+ # First call (git pull --tags) succeeds, second call (git cliff) raises FileNotFoundError
142+ mock_run .side_effect = [
143+ subprocess .CompletedProcess (args = [], returncode = 0 , stdout = "" , stderr = "" ),
144+ FileNotFoundError ,
145+ ]
141146 with pytest .raises (SystemExit ):
142147 run_git_cliff ()
143148
@@ -322,6 +327,59 @@ def test_run_git_cliff_with_version_tag(mock_subprocess_run, mock_find_config):
322327 assert "--tag" in executed_cmd and "1.0.0" in executed_cmd
323328
324329
330+ @patch (
331+ "openwisp_utils.releaser.changelog.find_cliff_config" ,
332+ return_value = "path/to/cliff.toml" ,
333+ )
334+ @patch ("openwisp_utils.releaser.changelog.subprocess.run" )
335+ def test_run_git_cliff_calls_git_pull_tags (mock_subprocess_run , mock_find_config ):
336+ """Tests that `git pull --tags` is executed before running git-cliff."""
337+ # Mock the subprocess.run to return different results for different calls
338+ mock_subprocess_run .return_value = subprocess .CompletedProcess (
339+ args = [], returncode = 0 , stdout = "Changelog content" , stderr = ""
340+ )
341+ run_git_cliff ()
342+ # Verify that subprocess.run was called twice: once for git pull --tags, once for git-cliff
343+ assert mock_subprocess_run .call_count == 2
344+ # Check the first call is for git pull --tags
345+ first_call_args = mock_subprocess_run .call_args_list [0 ][0 ][0 ]
346+ assert first_call_args == ["git" , "pull" , "--tags" ]
347+ # Check the second call is for git cliff
348+ second_call_args = mock_subprocess_run .call_args_list [1 ][0 ][0 ]
349+ assert (
350+ "git" in second_call_args
351+ and "cliff" in second_call_args
352+ and "--unreleased" in second_call_args
353+ )
354+
355+
356+ @patch (
357+ "openwisp_utils.releaser.changelog.find_cliff_config" ,
358+ return_value = "path/to/cliff.toml" ,
359+ )
360+ @patch ("openwisp_utils.releaser.changelog.subprocess.run" )
361+ @patch ("builtins.print" )
362+ def test_run_git_cliff_git_pull_tags_fails (
363+ mock_print , mock_subprocess_run , mock_find_config
364+ ):
365+ """Tests that `git pull --tags` failure is handled gracefully and git-cliff still runs."""
366+ # First call (git pull --tags) fails, second call (git cliff) succeeds
367+ mock_subprocess_run .side_effect = [
368+ subprocess .CalledProcessError (1 , "git pull --tags" , stderr = "Network error" ),
369+ subprocess .CompletedProcess (
370+ args = [], returncode = 0 , stdout = "Changelog content" , stderr = ""
371+ ),
372+ ]
373+ run_git_cliff ()
374+ # Verify that subprocess.run was called twice despite the first failure
375+ assert mock_subprocess_run .call_count == 2
376+ # Verify warning message was printed
377+ mock_print .assert_called_once ()
378+ call_args = mock_print .call_args [0 ][0 ]
379+ assert "Warning: Failed to pull tags:" in call_args
380+ assert "Network error" in call_args
381+
382+
325383def test_process_changelog_dependencies_as_last_section ():
326384 """Tests where 'Dependencies' is the last section."""
327385 changelog_text = (
0 commit comments