Description
When docs_dir is set to the repository root (. or the same path as the git toplevel), the load_git_metadata() function returns an empty dictionary despite valid git history being available. This causes the plugin to fall back to site_author and filesystem timestamps instead of using git data.
Environment
- mkdocs-document-dates: 3.8.5
- mkdocs-materialx: 10.1.6
- properdocs: 1.6.7
- Python: 3.14
- OS: Tested on macOS (native) and Alpine Linux (Docker container)
Reproduction
- Create a repository where markdown files live at the root (no
docs/ subdirectory)
- Configure mkdocs with
docs_dir pointing to the repo root:
docs_dir: !ENV [MKDOCS_DOCS_DIR, 'docs']
# At runtime, MKDOCS_DOCS_DIR is set to the repo root
- Enable the plugin:
plugins:
- document-dates:
position: top
type: timeago
show_created: true
show_updated: true
show_author: true
- Build the site. Authors display as
site_author fallback and dates are filesystem timestamps, not git dates.
Root Cause
In utils.py, load_git_metadata() computes:
git_root = Path(subprocess.check_output(
['git', 'rev-parse', '--show-toplevel'],
cwd=docs_dir_path, encoding='utf-8'
).strip())
rel_docs_path = docs_dir_path.relative_to(git_root).as_posix()
When docs_dir_path equals git_root, rel_docs_path resolves to '.'.
The git command that follows works correctly:
git -c core.quotepath=false log --reverse --no-merges --use-mailmap \
--name-only -z --format='%aN%x1f%aE%x1f%at%x1f%B%x00' \
--relative=. -- '*.md'
This returns valid output (verified: 72KB of commit data in our repo). However, the parsing logic that processes the output appears to fail when rel_docs_path is '.', resulting in an empty dates_cache dictionary.
Verification
from pathlib import Path
from mkdocs_document_dates.utils import load_git_metadata
# Returns empty dict when run from repo root
data = load_git_metadata(Path('.'))
print(data) # {}
# But the underlying git command returns valid data
import subprocess
cmd = ['git', '-c', 'core.quotepath=false', 'log', '--reverse', '--no-merges',
'--use-mailmap', '--name-only', '-z', '--format=%aN%x1f%aE%x1f%at%x1f%B%x00',
'--relative=.', '--', '*.md']
result = subprocess.run(cmd, capture_output=True, encoding='utf-8')
print(f"stdout length: {len(result.stdout)}") # 72656 bytes
Expected Behavior
load_git_metadata() should correctly parse git log output and return date/author data for all markdown files when docs_dir is the repository root.
Workaround
None currently. Using git-revision-date-localized plugin as an alternative for dates, but it lacks native template integration with materialx.
Description
When
docs_diris set to the repository root (.or the same path as the git toplevel), theload_git_metadata()function returns an empty dictionary despite valid git history being available. This causes the plugin to fall back tosite_authorand filesystem timestamps instead of using git data.Environment
Reproduction
docs/subdirectory)docs_dirpointing to the repo root:site_authorfallback and dates are filesystem timestamps, not git dates.Root Cause
In
utils.py,load_git_metadata()computes:When
docs_dir_pathequalsgit_root,rel_docs_pathresolves to'.'.The git command that follows works correctly:
git -c core.quotepath=false log --reverse --no-merges --use-mailmap \ --name-only -z --format='%aN%x1f%aE%x1f%at%x1f%B%x00' \ --relative=. -- '*.md'This returns valid output (verified: 72KB of commit data in our repo). However, the parsing logic that processes the output appears to fail when
rel_docs_pathis'.', resulting in an emptydates_cachedictionary.Verification
Expected Behavior
load_git_metadata()should correctly parse git log output and return date/author data for all markdown files whendocs_diris the repository root.Workaround
None currently. Using
git-revision-date-localizedplugin as an alternative for dates, but it lacks native template integration with materialx.