Skip to content

Commit 5536835

Browse files
committed
Simplify count_commits() and add unit tests, closes #67
1 parent 91eb3b4 commit 5536835

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

mkdocs_git_revision_date_localized_plugin/ci.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def raise_ci_warnings(repo) -> None:
2020

2121
n_commits = commit_count(repo)
2222

23+
2324
# Gitlab Runners
2425
if os.getenv("GITLAB_CI") is not None and n_commits < 50:
2526
# Default is GIT_DEPTH of 50 for gitlab
@@ -85,11 +86,7 @@ def commit_count(repo) -> int:
8586
Returns:
8687
count (int): Number of commits.
8788
"""
88-
refs = repo.for_each_ref().split("\n")
89-
refs = [x.split()[0] for x in refs]
90-
91-
counts = [int(repo.rev_list(x, count=True, first_parent=True)) for x in refs]
92-
return max(counts)
89+
return int(repo.rev_list('--count','HEAD'))
9390

9491

9592
def is_shallow_clone(repo) -> bool:

tests/test_builds.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
# package module
3030
from mkdocs_git_revision_date_localized_plugin.util import Util
31+
from mkdocs_git_revision_date_localized_plugin.ci import commit_count
3132

3233
# ##################################
3334
# ######## Globals #################
@@ -339,7 +340,13 @@ def test_tags_are_replaced(tmp_path, mkdocs_file):
339340

340341
if plugin_config.get("type") == "timeago":
341342
pytest.skip("Not necessary to test the JS library")
342-
343+
344+
# Make sure count_commits() works
345+
# We created 8 commits in setup_commit_history()
346+
with working_directory(testproject_path):
347+
u = Util()
348+
assert commit_count(u._get_repo("docs/page_with_tag.md")) == 8
349+
343350

344351
# the revision date was in 'setup_commit_history' was set to 1642911026 (Sun Jan 23 2022 04:10:26 GMT+0000)
345352
# Assert {{ git_revision_date_localized }} is replaced

0 commit comments

Comments
 (0)