old_contents: # -*- coding: utf-8 -*-
  
  import subprocess
  
  GIT_CMD = 'git log | head -3'
  
  def git_stats():
    try:
      ret = subprocess.check_output([GIT_CMD], shell=True)\
        .decode('utf-8')\
        .split("\n")
      if len(ret) >= 3:
        commit = ret[0].split()[1]
        author = (" ").join(ret[1].split()[1:])
        date = (" ").join(ret[2].split()[1:])
        return {
          "commit": commit,
          "author": author,
          "date":   date
        }
      else:
        return {}
    except subprocess.CalledProcessError:
      return {}
  
new_contents: # -*- coding: utf-8 -*-
  
  import subprocess, re
  
  GIT_CMD = 'git log | head -4'
  RE_COMMIT = re.compile(r'commit[\W]+(\w+)', re.MULTILINE)
  RE_AUTHOR = re.compile(r'Author\:[\W]+(.*)', re.MULTILINE)
  RE_DATE = re.compile(r'Date\:[\W]+(.*)', re.MULTILINE)
  
  def git_stats():
    try:
      ret = subprocess.check_output([GIT_CMD], shell=True)\
        .decode('utf-8')
      commit = re.search(RE_COMMIT, ret)
      author = re.search(RE_AUTHOR, ret)
      date = re.search(RE_DATE, ret)
      return {
        "commit": commit.group(1) if commit else "Unknown",
        "author": author.group(1) if author else "Unknown",
        "date":   date.group(1) if date else "Unknown"
      }
    except subprocess.CalledProcessError:
      return { "Error" }
  
subject: Switch to regex matching