]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Avoid exception when 'git log' output is unexpected.
authorBruno Haible <bruno@clisp.org>
Wed, 28 Feb 2024 10:38:00 +0000 (11:38 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 28 Feb 2024 10:38:00 +0000 (11:38 +0100)
* pygnulib/GLInfo.py (GLInfo.date): When the 'git log' output does not
contain a line with the expected 'Date:' pattern, pass the empty string
to GNU date.

ChangeLog
pygnulib/GLInfo.py

index af0835269fe2b6986604d1380785aeb07d0ee68c..e667861d9cc766410a724ec29ecff97e11a904d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-02-28  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool.py: Avoid exception when 'git log' output is unexpected.
+       * pygnulib/GLInfo.py (GLInfo.date): When the 'git log' output does not
+       contain a line with the expected 'Date:' pattern, pass the empty string
+       to GNU date.
+
 2024-02-28  Bruno Haible  <bruno@clisp.org>
 
        gnulib-tool: Avoid references to functions that get defined later.
index 808f11b06feb0c22b028aebd15adc9d23e004ed7..8ffe1d309bc5899942d1d6f82b0c87afb93dc65d 100644 (file)
@@ -106,10 +106,14 @@ class GLInfo(object):
                     result = sp.check_output(args, cwd=DIRS['root']).decode("UTF-8")
                     # Get date as "Fri Mar 21 07:16:51 2008 -0600" from string
                     pattern = re.compile('^Date:[\t ]*(.*?)$', re.M)
-                    result = pattern.findall(result)[0]
-                    # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600"
-                    pattern = re.compile('^[^ ]* ([^ ]*) ([0-9]*) ([0-9:]*) ([0-9]*) ')
-                    result = pattern.sub('\\1 \\2 \\4 \\3 ', result)
+                    result = pattern.findall(result)
+                    if (len(result) > 0):
+                        result = result[0]
+                        # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600"
+                        pattern = re.compile('^[^ ]* ([^ ]*) ([0-9]*) ([0-9:]*) ([0-9]*) ')
+                        result = pattern.sub('\\1 \\2 \\4 \\3 ', result)
+                    else:
+                        result = ''
                     # Use GNU date to compute the time in GMT
                     args = ['date', '-d', result, '-u', '+%Y-%m-%d %H:%M:%S']
                     proc = sp.check_output(args)