prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  pre-commit autoupdate fails when config is empty
  Running `pre-commit autoupdate` with an empty `.pre-commit-config.yaml` results in the below error:
  ```An unexpected error has occurred: IndexError: list index out of range
  Traceback (most recent call last):
    File "/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/error_handler.py", line 46, in error_handler
      yield
    File "/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/main.py", line 286, in main
      repos=args.repos,
    File "/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/commands/autoupdate.py", line 117, in autoupdate
      migrate_config(config_file, quiet=True)
    File "/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/commands/migrate_config.py", line 52, in migrate_config
      contents = _migrate_map(contents)
    File "/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/commands/migrate_config.py", line 24, in _migrate_map
      while _is_header_line(lines[i]):
  IndexError: list index out of range
  ```
  
  </issue>
  <code>
  [start of pre_commit/commands/migrate_config.py]
  1 from __future__ import print_function
  2 from __future__ import unicode_literals
  3 
  4 import io
  5 import re
  6 
  7 import yaml
  8 from aspy.yaml import ordered_load
  9 
  10 
  11 def _indent(s):
  12     lines = s.splitlines(True)
  13     return ''.join(' ' * 4 + line if line.strip() else line for line in lines)
  14 
  15 
  16 def _is_header_line(line):
  17     return (line.startswith(('#', '---')) or not line.strip())
  18 
  19 
  20 def _migrate_map(contents):
  21     # Find the first non-header line
  22     lines = contents.splitlines(True)
  23     i = 0
  24     while _is_header_line(lines[i]):
  25         i += 1
  26 
  27     header = ''.join(lines[:i])
  28     rest = ''.join(lines[i:])
  29 
  30     if isinstance(ordered_load(contents), list):
  31         # If they are using the "default" flow style of yaml, this operation
  32         # will yield a valid configuration
  33         try:
  34             trial_contents = header + 'repos:\n' + rest
  35             ordered_load(trial_contents)
  36             contents = trial_contents
  37         except yaml.YAMLError:
  38             contents = header + 'repos:\n' + _indent(rest)
  39 
  40     return contents
  41 
  42 
  43 def _migrate_sha_to_rev(contents):
  44     reg = re.compile(r'(\n\s+)sha:')
  45     return reg.sub(r'\1rev:', contents)
  46 
  47 
  48 def migrate_config(config_file, quiet=False):
  49     with io.open(config_file) as f:
  50         orig_contents = contents = f.read()
  51 
  52     contents = _migrate_map(contents)
  53     contents = _migrate_sha_to_rev(contents)
  54 
  55     if contents != orig_contents:
  56         with io.open(config_file, 'w') as f:
  57             f.write(contents)
  58 
  59         print('Configuration has been migrated.')
  60     elif not quiet:
  61         print('Configuration is already migrated.')
  62
  [end of pre_commit/commands/migrate_config.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pre_commit/commands/migrate_config.py b/pre_commit/commands/migrate_config.py
  --- a/pre_commit/commands/migrate_config.py
  +++ b/pre_commit/commands/migrate_config.py
  @@ -21,7 +21,8 @@
       # Find the first non-header line
       lines = contents.splitlines(True)
       i = 0
  -    while _is_header_line(lines[i]):
  +    # Only loop on non empty configuration file
  +    while i < len(lines) and _is_header_line(lines[i]):
           i += 1
   
       header = ''.join(lines[:i])
  
verification_info: {"golden_diff": "diff --git a/pre_commit/commands/migrate_config.py b/pre_commit/commands/migrate_config.py\n--- a/pre_commit/commands/migrate_config.py\n+++ b/pre_commit/commands/migrate_config.py\n@@ -21,7 +21,8 @@\n     # Find the first non-header line\n     lines = contents.splitlines(True)\n     i = 0\n-    while _is_header_line(lines[i]):\n+    # Only loop on non empty configuration file\n+    while i < len(lines) and _is_header_line(lines[i]):\n         i += 1\n \n     header = ''.join(lines[:i])\n", "issue": "pre-commit autoupdate fails when config is empty\nRunning `pre-commit autoupdate` with an empty `.pre-commit-config.yaml` results in the below error:\r\n```An unexpected error has occurred: IndexError: list index out of range\r\nTraceback (most recent call last):\r\n  File \"/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/error_handler.py\", line 46, in error_handler\r\n    yield\r\n  File \"/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/main.py\", line 286, in main\r\n    repos=args.repos,\r\n  File \"/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/commands/autoupdate.py\", line 117, in autoupdate\r\n    migrate_config(config_file, quiet=True)\r\n  File \"/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/commands/migrate_config.py\", line 52, in migrate_config\r\n    contents = _migrate_map(contents)\r\n  File \"/usr/local/Cellar/pre-commit/1.14.2/libexec/lib/python3.7/site-packages/pre_commit/commands/migrate_config.py\", line 24, in _migrate_map\r\n    while _is_header_line(lines[i]):\r\nIndexError: list index out of range\r\n```\n", "before_files": [{"content": "from __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport io\nimport re\n\nimport yaml\nfrom aspy.yaml import ordered_load\n\n\ndef _indent(s):\n    lines = s.splitlines(True)\n    return ''.join(' ' * 4 + line if line.strip() else line for line in lines)\n\n\ndef _is_header_line(line):\n    return (line.startswith(('#', '---')) or not line.strip())\n\n\ndef _migrate_map(contents):\n    # Find the first non-header line\n    lines = contents.splitlines(True)\n    i = 0\n    while _is_header_line(lines[i]):\n        i += 1\n\n    header = ''.join(lines[:i])\n    rest = ''.join(lines[i:])\n\n    if isinstance(ordered_load(contents), list):\n        # If they are using the \"default\" flow style of yaml, this operation\n        # will yield a valid configuration\n        try:\n            trial_contents = header + 'repos:\\n' + rest\n            ordered_load(trial_contents)\n            contents = trial_contents\n        except yaml.YAMLError:\n            contents = header + 'repos:\\n' + _indent(rest)\n\n    return contents\n\n\ndef _migrate_sha_to_rev(contents):\n    reg = re.compile(r'(\\n\\s+)sha:')\n    return reg.sub(r'\\1rev:', contents)\n\n\ndef migrate_config(config_file, quiet=False):\n    with io.open(config_file) as f:\n        orig_contents = contents = f.read()\n\n    contents = _migrate_map(contents)\n    contents = _migrate_sha_to_rev(contents)\n\n    if contents != orig_contents:\n        with io.open(config_file, 'w') as f:\n            f.write(contents)\n\n        print('Configuration has been migrated.')\n    elif not quiet:\n        print('Configuration is already migrated.')\n", "path": "pre_commit/commands/migrate_config.py"}]}