Skip to content

Commit e38f178

Browse files
Add --keep-original-year flag to allow stale years to be unchanged (#78)
Co-authored-by: Lucas Cimon <[email protected]>
1 parent 459d044 commit e38f178

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ headers:
109109
years they contain -- as if they used the year currently present in the
110110
license file.
111111

112+
You can also use `--allow-past-years` to allow stale years to be unchanged.
113+
Using both `--allow-past-years` and `--use-current-year` issues a year
114+
range as described above.
115+
112116
#### No extra EOL
113117

114118
The `--no-extra-eol` argument prevents the insertion of an additional

pre_commit_hooks/insert_license.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,19 @@ def main(argv=None):
8787
"--use-current-year",
8888
action="store_true",
8989
help=(
90-
"Allow past years and ranges of years in headers. Use the current year in inserted and updated licenses."
90+
"Use the current year in inserted and updated licenses, implies --allow-past-years"
91+
),
92+
)
93+
parser.add_argument(
94+
"--allow-past-years",
95+
action="store_true",
96+
help=(
97+
"Allow past years in headers. License comments are not updated if they contain past years."
9198
),
9299
)
93100
args = parser.parse_args(argv)
101+
if args.use_current_year:
102+
args.allow_past_years = True
94103

95104
license_info = get_license_info(args)
96105

@@ -201,7 +210,7 @@ def process_files(args, changed_files, todo_files, license_info: LicenseInfo):
201210
src_file_content=src_file_content,
202211
license_info=license_info,
203212
top_lines_count=args.detect_license_in_X_top_lines,
204-
match_years_strictly=not args.use_current_year,
213+
match_years_strictly=not args.allow_past_years,
205214
)
206215
fuzzy_match_header_index = None
207216
if args.fuzzy_match_generates_todo and license_header_index is None:

tests/insert_license_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@
193193
True,
194194
["--use-current-year"],
195195
),
196+
(
197+
"module_with_stale_year_range_in_license.py",
198+
"#",
199+
"module_with_stale_year_range_in_license.py",
200+
"",
201+
False,
202+
["--allow-past-years"],
203+
),
196204
(
197205
"module_with_badly_formatted_stale_year_range_in_license.py",
198206
"#",

0 commit comments

Comments
 (0)