Skip to content

Commit

Permalink
added check to hook updates to avoid attempting to update the local repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Bowden committed Jun 24, 2024
1 parent 4d8ffb1 commit 62ad62e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion secureli/modules/shared/abstractions/pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 22 additions & 1 deletion tests/modules/shared/abstractions/test_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
):
Expand Down

0 comments on commit 62ad62e

Please sign in to comment.