
import subprocess
from ..utils import DEVNULL, change_working_directory
from .base import DOWNLOAD_CONTAINER


def download(source_info):
    url = source_info['git']
    subprocess.call(
        ('git', 'clone', url, DOWNLOAD_CONTAINER),
        stdout=DEVNULL, stderr=subprocess.STDOUT,
    )
    if 'tag' in source_info:
        with change_working_directory(DOWNLOAD_CONTAINER):
            subprocess.call(
                ('git', 'checkout', source_info['tag']),
                stdout=DEVNULL, stderr=subprocess.STDOUT,
            )


import subprocess
from ..utils import DEVNULL, change_working_directory
from .base import DOWNLOAD_CONTAINER


def _checkout(name):
    with change_working_directory(DOWNLOAD_CONTAINER):
        subprocess.call(
            ('git', 'checkout', name),
            stdout=DEVNULL, stderr=subprocess.STDOUT,
        )


def download(source_info):
    url = source_info['git']
    subprocess.call(
        ('git', 'clone', url, DOWNLOAD_CONTAINER),
        stdout=DEVNULL, stderr=subprocess.STDOUT,
    )
    if 'tag' in source_info:
        _checkout(source_info['tag'])
    elif 'branch' in source_info:
        _checkout(source_info['branch'])

Add auto branch checkout functionality
Add auto branch checkout functionality

  
  import subprocess
  from ..utils import DEVNULL, change_working_directory
  from .base import DOWNLOAD_CONTAINER
+ 
+ 
+ def _checkout(name):
+     with change_working_directory(DOWNLOAD_CONTAINER):
+         subprocess.call(
+             ('git', 'checkout', name),
+             stdout=DEVNULL, stderr=subprocess.STDOUT,
+         )
  
  
  def download(source_info):
      url = source_info['git']
      subprocess.call(
          ('git', 'clone', url, DOWNLOAD_CONTAINER),
          stdout=DEVNULL, stderr=subprocess.STDOUT,
      )
      if 'tag' in source_info:
-         with change_working_directory(DOWNLOAD_CONTAINER):
-             subprocess.call(
-                 ('git', 'checkout', source_info['tag']),
+         _checkout(source_info['tag'])
-                 stdout=DEVNULL, stderr=subprocess.STDOUT,
-             )
+     elif 'branch' in source_info:
+         _checkout(source_info['branch'])
  
Add auto branch checkout functionality
## Code Before:

import subprocess
from ..utils import DEVNULL, change_working_directory
from .base import DOWNLOAD_CONTAINER


def download(source_info):
    url = source_info['git']
    subprocess.call(
        ('git', 'clone', url, DOWNLOAD_CONTAINER),
        stdout=DEVNULL, stderr=subprocess.STDOUT,
    )
    if 'tag' in source_info:
        with change_working_directory(DOWNLOAD_CONTAINER):
            subprocess.call(
                ('git', 'checkout', source_info['tag']),
                stdout=DEVNULL, stderr=subprocess.STDOUT,
            )

## Instruction:
Add auto branch checkout functionality
## Code After:

import subprocess
from ..utils import DEVNULL, change_working_directory
from .base import DOWNLOAD_CONTAINER


def _checkout(name):
    with change_working_directory(DOWNLOAD_CONTAINER):
        subprocess.call(
            ('git', 'checkout', name),
            stdout=DEVNULL, stderr=subprocess.STDOUT,
        )


def download(source_info):
    url = source_info['git']
    subprocess.call(
        ('git', 'clone', url, DOWNLOAD_CONTAINER),
        stdout=DEVNULL, stderr=subprocess.STDOUT,
    )
    if 'tag' in source_info:
        _checkout(source_info['tag'])
    elif 'branch' in source_info:
        _checkout(source_info['branch'])
