Skip to content

Commit 5948673

Browse files
committed
WA for git log --follow behavior
1 parent b8f6a58 commit 5948673

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/test_check_copyright_headers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,19 @@ def prepare_copyright_with_year(file: Path, line: str) -> str:
5050
capture_output=True,
5151
text=True,
5252
)
53-
curr_year_spec = line.split(" ")[3]
54-
spec_is_range = "-" in curr_year_spec
55-
53+
if not res.stdout:
54+
# in some cases when a file was renamed, --follow won't allow getting the last modified year
55+
res = subprocess.run(
56+
["git", "log", "--format=%ad", "--date=format:%Y", "-1", file],
57+
capture_output=True,
58+
text=True,
59+
)
5660
changed_years = res.stdout.splitlines()
5761
last_modified_year_real = int(changed_years[0])
5862

63+
curr_year_spec = line.split(" ")[3]
64+
spec_is_range = "-" in curr_year_spec
65+
5966
after_year_str = "NVIDIA CORPORATION & AFFILIATES. All rights reserved."
6067

6168
if spec_is_range:

0 commit comments

Comments
 (0)