def split_header(diff):
  """Splits a diff in two: the header and the chunks."""
  header = []
  chunks = diff.splitlines(True)
  while chunks:
    if chunks[0].startswith('--- '):
      break
    header.append(chunks.pop(0))
  else:
    # Some diff may not have a ---/+++ set like a git rename with no change or
    # a permissions change.
    pass

  if chunks:
    assert chunks[0].startswith('--- '), 'Inconsistent header'
  return ''.join(header), ''.join(chunks)