-
-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Description
hawkeye_fmt::git::resolve_file_attrs relies on head.ancestors().all() to traverse the commits in a certain order and compare their working trees. However, when the git history is not linear and involves merge-commits, improper traversal orders can leads to wrong attrs.git_file_{created,modified}_year.
Reproduce
#!/usr/bin/env bash
set -euo pipefail
git init
cat > licenserc.toml <<EOF
inlineHeader = "{{attrs.git_file_created_year}} - {{attrs.git_file_modified_year}}"
excludes = ["licenserc.toml"]
[git]
ignore = "enable"
attrs = "enable"
EOF
git add licenserc.toml
echo foo > COMMON1.md
echo foo > COMMON2.md
git add COMMON1.md
git add COMMON2.md
GIT_COMMITTER_DATE="2025-12-15T00:00:00Z" git commit -m 'init'
echo foo >> COMMON1.md
GIT_COMMITTER_DATE="2025-12-22T00:00:00Z" git commit -a -m 'base'
git branch wip
echo "// 2025 - 2025" > A.rs
git add A.rs
GIT_COMMITTER_DATE="2025-12-30T00:00:00Z" git commit -m 'mA2025'
echo "// 2026 - 2026" > B.rs
git add B.rs
GIT_COMMITTER_DATE="2026-01-05T00:00:00Z" git commit -m 'mB2026'
echo foo >> COMMON1.md
GIT_COMMITTER_DATE="2026-01-07T00:00:00Z" git commit -a -m 'dummy'
echo foo >> COMMON1.md
GIT_COMMITTER_DATE="2026-01-08T00:00:00Z" git commit -a -m 'random'
git checkout wip
echo foo >> COMMON2.md
GIT_COMMITTER_DATE="2026-01-06T00:00:00Z" git commit -a -m 'w'
git checkout main
git merge wip --no-editExpected
No Errors. A.rs is created and last modified in 2025. B.rs is created and last modified in 2026.
Actual
hawkeye format wants to update both files to 2025 - 2026.
Details
The repro above has the following history:
main: init - base - mA2025 - mB2026 --- dummy - random - merge
wip: +------------------- w ------------------+
The current traversal order is:
merge - random - w - dummy - base - mB2026 - init - mA2025
- When
next_commit = baseandthis_commit = mB2026, the worktree diff would contain deletion ofB.rsat commit time ofbase, leading to wrongcreatedtime ofB.rsbeing2025. - When
next_commit = randomandthis_commit = w, the worktree diff would contain addition ofA.rsat commit time ofrandom, leading to wrongupdatedtime ofA.rsbeing2026.
Potential workarounds/solutions
- Give up on supporting merge-commit and clearly require linear history in README.
- Especially, users of
actions/checkoutneed to configurerefto HEAD rather than defaulting to merge commit.
- Especially, users of
- Pass
Sorting::ByCommitTimetogixinstead of the defaultBreadthFirst. This can fixcreatedbutmodifiedis still wrong. - Avoid relying on traversal order and worktree diff. Find other ways to identify file changes inside a commit.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels