From b13fa6192da1b4309ba07ecb5a8834ec7d143fad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr>
Date: Mon, 27 Jan 2020 11:39:54 +0100
Subject: [PATCH] =?UTF-8?q?Utilise=20la=20date=20de=20dernier=20commit=20p?=
 =?UTF-8?q?lut=C3=B4t=20que=20la=20date=20courante=20pour=20les=20copyrigh?=
 =?UTF-8?q?ts.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Ça devrait limiter les faux positifs quand on teste un "vieux" code.
---
 src/Git/GitRepository.php | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/Git/GitRepository.php b/src/Git/GitRepository.php
index 50a4d0a..317dfac 100644
--- a/src/Git/GitRepository.php
+++ b/src/Git/GitRepository.php
@@ -45,12 +45,21 @@ final class GitRepository implements GitRepositoryInterface
      */
     public function getYearRange(): string
     {
-        $last = date('Y');
-        $first = exec('git -C ' . escapeshellarg($this->repositoryPath) . ' log --format=%cd --date=format:%Y --date-order | tail -n1');
-        if (!$first) {
-            $first = '???';
+        $years = [];
+        exec(
+            sprintf(
+                'git -C %s log --format=%%cd --date=format:%%Y --date-order %s | sed \'1p;$p;d\'',
+                escapeshellarg($this->repositoryPath),
+                escapeshellarg($this->getHeadCommit())
+            ),
+            $years
+        );
+        if (!$years) {
+            return '???';
         }
+        $last = trim(array_shift($years));
+        $first = $years ? trim(array_pop($years)) : $last;
 
-        return ($last !== null && $last !== $first) ? "$first-$last" : $first;
+        return $last !== $first ? "$first-$last" : $first;
     }
 }
-- 
GitLab