def checkout(self, ref, ref_is_sha, pull_after_update,
              stdout=sys.stdout, stderr=sys.stderr):
     if not os.path.exists(self.root_path):
         common.check_execute(['mkdir', '-p', self.root_path],
                              stdout=stdout, stderr=stderr)
     path = os.path.join(self.root_path, self.project['path'])
     if self.project['repository'] == 'Git':
         if os.path.exists(path):
             if ref_is_sha:
                 common.git_update(self.project['url'], ref, path,
                                   incremental=self.skip_clean,
                                   stdout=stdout, stderr=stderr)
             else:
                 if not self.skip_clean:
                     common.git_clean(path, stdout=stdout, stderr=stderr)
                 common.git_checkout(ref, path,
                                     force=True,
                                     stdout=stdout, stderr=stderr)
             if pull_after_update:
                 common.git_pull(path, stdout=stdout, stderr=stderr)
         else:
             common.git_clone(self.project['url'], path, ref,
                              stdout=stdout, stderr=stderr)
     else:
         raise common.Unreachable('Unsupported repository: %s' %
                                  self.project['repository'])
def checkout(root_path, repo, commit):
    """Checkout an indexed repository."""
    path = os.path.join(root_path, repo['path'])
    if repo['repository'] == 'Git':
        if os.path.exists(path):
            return common.git_update(repo['url'], commit, path)
        else:
            return common.git_clone(repo['url'], path, tree=commit)
    raise common.Unreachable('Unsupported repository: %s' % repo['repository'])