From 4df161fb5e101fcafa8b2163d4e6c40dd02b621f Mon Sep 17 00:00:00 2001 From: Tanner Doshier Date: Wed, 15 Jan 2025 15:46:13 -0500 Subject: [PATCH] Fix `update --force` against the same version --- nava/platform/templates/template.py | 7 +++--- .../cli/commands/infra/test_update_command.py | 24 ++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/nava/platform/templates/template.py b/nava/platform/templates/template.py index 6343463..eecf964 100644 --- a/nava/platform/templates/template.py +++ b/nava/platform/templates/template.py @@ -165,9 +165,10 @@ def update( self._checkout_copier_ref(version) - # if we are not just updating answers or providing data and are already - # running the version that would be installed, then skip - if (not answers_only or not passed_data) and self._is_same_version(existing_version): + # if we are already running the version that would be installed, then + # skip, unless overridden + bypass_same_version_check = force or (answers_only and passed_data) + if not bypass_same_version_check and self._is_same_version(existing_version): self.ctx.console.print(f"Already up to date ({existing_version.display_str})") return diff --git a/tests/cli/commands/infra/test_update_command.py b/tests/cli/commands/infra/test_update_command.py index 1cef13e..a50ed1d 100644 --- a/tests/cli/commands/infra/test_update_command.py +++ b/tests/cli/commands/infra/test_update_command.py @@ -12,19 +12,41 @@ def test_update_no_change(cli, infra_template, new_project, clean_install): content_before_update = DirectoryContent.from_fs(new_project.dir, ignore=[".git"]) - cli( + result = cli( + [ + "infra", + "update", + str(new_project.dir), + "--template-uri", + str(infra_template.template_dir), + ] + ) + + content_after_update = DirectoryContent.from_fs(new_project.dir, ignore=[".git"]) + assert content_before_update == content_after_update + + assert "Already up to date" in result.output + + +def test_update_no_change_force(cli, infra_template, new_project, clean_install): + content_before_update = DirectoryContent.from_fs(new_project.dir, ignore=[".git"]) + + result = cli( [ "infra", "update", str(new_project.dir), "--template-uri", str(infra_template.template_dir), + "--force", ] ) content_after_update = DirectoryContent.from_fs(new_project.dir, ignore=[".git"]) assert content_before_update == content_after_update + assert "Already up to date" not in result.output + def test_update_with_template_change(cli, infra_template, new_project, clean_install): ChangeSet(