Repository: Lucas-C/pre-commit-hooks

Issue:
[Enhancement] Update multiple licence year ends in one run. 
I have two lines with the licence year in my headers:

```text
/* Copyright (c) 2012-2023 Dummy             */
/*********************************************/
/* @copyright Copyright (c) 2012-2023 Dummy  */
```

On the first pre-commit execution, the first line is updated.
On the second pre-commit execution, the second line is updated.
On the third run, the commit is performed.

If one of the pre-commit runs could be avoided by changing both lines in a single run that would be great.

This is my configuration:

```yaml
  - repo: https://github.com/Lucas-C/pre-commit-hooks
    rev: v1.5.1
    hooks:
      - id: insert-license
        files: ^(.*\.(php))$
        args:
          - --license-filepath
          - doc/LICENSE
          - --use-current-year
          - --comment-style
          - ''
          - --no-space-in-comment-prefix
          - --fuzzy-match-extra-lines-to-check
          - '10'
          - --insert-license-after-regex
          - ^<\?php$
```

Note: My licence file is already updated like this:
```text
/* Copyright (c) 2012-2024 Dummy             */
/*********************************************/
/* @copyright Copyright (c) 2012-2024 Dummy  */
```

Discussion:

Patch:
diff --git a/pre_commit_hooks/insert_license.py b/pre_commit_hooks/insert_license.py
index 42a01b1..19c9929 100644
--- a/pre_commit_hooks/insert_license.py
+++ b/pre_commit_hooks/insert_license.py
@@ -396,14 +396,15 @@ def try_update_year_range(
     :return: source file contents and a flag indicating update
     """
     current_year = datetime.now().year
+    changed = False
     for i in range(license_header_index, license_header_index + license_length):
         updated = try_update_year(
             src_file_content[i], src_filepath, current_year, introduce_range=True
         )
         if updated:
             src_file_content[i] = updated
-            return src_file_content, True
-    return src_file_content, False
+            changed = True
+    return src_file_content, changed
 
 
 def license_found(


Test patch:
diff --git a/tests/insert_license_test.py b/tests/insert_license_test.py
index 2972849..85f2ef4 100644
--- a/tests/insert_license_test.py
+++ b/tests/insert_license_test.py
@@ -425,6 +425,20 @@ def _convert_line_ending(file_path, new_line_endings):
                     ),
                 ),
             ),
+            product(
+                ("LICENSE_with_multiple_year_ranges.txt",),
+                ("\n",),
+                (
+                    (
+                        "module_with_multiple_stale_years_in_license.py",
+                        "#",
+                        "module_with_multiple_years_in_license.py",
+                        "",
+                        True,
+                        ["--use-current-year"],
+                    ),
+                ),
+            ),
         ),
     ),
 )
diff --git a/tests/resources/LICENSE_with_multiple_year_ranges.txt b/tests/resources/LICENSE_with_multiple_year_ranges.txt
new file mode 100644
index 0000000..01fca7f
--- /dev/null
+++ b/tests/resources/LICENSE_with_multiple_year_ranges.txt
@@ -0,0 +1,5 @@
+Copyright (C) 2016-2017 Teela O'Malley
+
+Licensed under the Apache License, Version 2.0 (the "License");
+
+@copyright 2012-2015 Teela O'Malley
\ No newline at end of file
diff --git a/tests/resources/module_with_multiple_stale_years_in_license.py b/tests/resources/module_with_multiple_stale_years_in_license.py
new file mode 100644
index 0000000..cfeac1b
--- /dev/null
+++ b/tests/resources/module_with_multiple_stale_years_in_license.py
@@ -0,0 +1,8 @@
+# Copyright (C) 2012-2015 Teela O'Malley
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+#
+# @copyright 2012-2015 Teela O'Malley
+
+import sys
+sys.stdout.write("FOO")
diff --git a/tests/resources/module_with_multiple_years_in_license.py b/tests/resources/module_with_multiple_years_in_license.py
new file mode 100644
index 0000000..eaf5cdf
--- /dev/null
+++ b/tests/resources/module_with_multiple_years_in_license.py
@@ -0,0 +1,8 @@
+# Copyright (C) 2012-2017 Teela O'Malley
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+#
+# @copyright 2012-2017 Teela O'Malley
+
+import sys
+sys.stdout.write("FOO")