import subprocess
import re
import json
import pprint

cmd = "git whatchanged --summary | grep rename | grep '=>' | grep '/task.'"
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
rename_map = {}

for line in proc.stdout:
  m = re.search(r'{(.*) => (.*)}', str(line))
  if not m:
    continue
  from_task = m.group(1)
  to_task = m.group(2)
  if '/' in from_task or '/' in to_task:
    # These are subtasks getting moved around
    continue
  if len(from_task) == 0 or len(to_task) == 0:
    # These are e.g. tasks becoming subtasks
    continue
  rename_map[from_task] = to_task

pprint.pprint(rename_map)
