Skip to content

Commit d50596b

Browse files
authored
Update multiple licence year ends in one run - close #94 (#98)
1 parent b26c56d commit d50596b

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

pre_commit_hooks/insert_license.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,15 @@ def try_update_year_range(
396396
:return: source file contents and a flag indicating update
397397
"""
398398
current_year = datetime.now().year
399+
changed = False
399400
for i in range(license_header_index, license_header_index + license_length):
400401
updated = try_update_year(
401402
src_file_content[i], src_filepath, current_year, introduce_range=True
402403
)
403404
if updated:
404405
src_file_content[i] = updated
405-
return src_file_content, True
406-
return src_file_content, False
406+
changed = True
407+
return src_file_content, changed
407408

408409

409410
def license_found(

tests/insert_license_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ def _convert_line_ending(file_path, new_line_endings):
425425
),
426426
),
427427
),
428+
product(
429+
("LICENSE_with_multiple_year_ranges.txt",),
430+
("\n",),
431+
(
432+
(
433+
"module_with_multiple_stale_years_in_license.py",
434+
"#",
435+
"module_with_multiple_years_in_license.py",
436+
"",
437+
True,
438+
["--use-current-year"],
439+
),
440+
),
441+
),
428442
),
429443
),
430444
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright (C) 2016-2017 Teela O'Malley
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
5+
@copyright 2012-2015 Teela O'Malley
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (C) 2012-2015 Teela O'Malley
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
#
5+
# @copyright 2012-2015 Teela O'Malley
6+
7+
import sys
8+
sys.stdout.write("FOO")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (C) 2012-2017 Teela O'Malley
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
#
5+
# @copyright 2012-2017 Teela O'Malley
6+
7+
import sys
8+
sys.stdout.write("FOO")

0 commit comments

Comments
 (0)