From 62ad62e9c205165fd4d38ff3511df3e9e07f0c40 Mon Sep 17 00:00:00 2001 From: Ian Bowden Date: Mon, 24 Jun 2024 12:47:54 -0400 Subject: [PATCH] added check to hook updates to avoid attempting to update the local repo --- .../modules/shared/abstractions/pre_commit.py | 2 +- .../shared/abstractions/test_pre_commit.py | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/secureli/modules/shared/abstractions/pre_commit.py b/secureli/modules/shared/abstractions/pre_commit.py index 5c4fae09..4faf3f60 100644 --- a/secureli/modules/shared/abstractions/pre_commit.py +++ b/secureli/modules/shared/abstractions/pre_commit.py @@ -192,7 +192,7 @@ def check_for_hook_updates( } # PreCommitSettings uses "url" instead of "repo", so we need to copy that value over old_rev_info = HookRepoRevInfo.from_config(repo_config_dict) - # if the repo doesn't appear to be valid, don't try to update it + # don't try and update the local repo if old_rev_info.repo == "local": continue diff --git a/tests/modules/shared/abstractions/test_pre_commit.py b/tests/modules/shared/abstractions/test_pre_commit.py index ef947336..6467bd2f 100644 --- a/tests/modules/shared/abstractions/test_pre_commit.py +++ b/tests/modules/shared/abstractions/test_pre_commit.py @@ -646,7 +646,7 @@ def test_check_for_hook_updates_returns_repos_with_new_revs( assert updated_repos[repo_urls[0]].newRev == "tag2" -def test_check_for_hook_updates_does_not_updated_repos_with_urls( +def test_check_for_hook_updates_updates_repos_not_named_local( pre_commit: PreCommitAbstractionModels.PreCommitAbstraction, ): with um.patch( @@ -669,6 +669,27 @@ def test_check_for_hook_updates_does_not_updated_repos_with_urls( rev_info_mock.update.assert_called_with(tags_only=True, freeze=True) +def test_check_for_hook_updates_does_not_update_repos_named_local( + pre_commit: PreCommitAbstractionModels.PreCommitAbstraction, +): + with um.patch( + "secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo.from_config" + ) as mock_hook_repo_rev_info: + pre_commit_config_repo = RepositoryModels.PreCommitRepo( + repo="local", + rev="tag1", + hooks=[RepositoryModels.PreCommitHook(id="hook-id")], + ) + pre_commit_config = RepositoryModels.PreCommitSettings( + repos=[pre_commit_config_repo] + ) + rev_info_mock = MagicMock(rev=pre_commit_config_repo.rev, repo="local") + mock_hook_repo_rev_info.return_value = rev_info_mock + rev_info_mock.update.return_value = rev_info_mock # Returning the same revision info on update means the hook will be considered up to date + pre_commit.check_for_hook_updates(pre_commit_config, freeze=True) + rev_info_mock.update.assert_not_called() + + def test_pre_commit_config_exists( pre_commit: PreCommitAbstractionModels.PreCommitAbstraction, ):