Skip to content

Commit 597ae12

Browse files
authored
Merge pull request #84 from timvink/67-more-robust-count-commits
Simplify count_commits() and add unit tests, closes #67
2 parents 84b0aeb + 5536835 commit 597ae12

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 #################
@@ -350,7 +351,13 @@ def test_tags_are_replaced(tmp_path, mkdocs_file):
350351

351352
if plugin_config.get("type") == "timeago":
352353
pytest.skip("Not necessary to test the JS library")
353-
354+
355+
# Make sure count_commits() works
356+
# We created 8 commits in setup_commit_history()
357+
with working_directory(testproject_path):
358+
u = Util()
359+
assert commit_count(u._get_repo("docs/page_with_tag.md")) == 8
360+
354361

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

0 commit comments

Comments
 (0)