# Path: nuka/tasks/apt.py
# GPG_HEADER = b'-----BEGIN PGP PUBLIC KEY BLOCK-----'
# def apt_watcher(delay, fd):
#     def watcher(task, process):
#     def __init__(self, name=None, src=None, key=None, update=True, **kwargs):
#     def add_key(self, key):
#     def do(self):
#     def diff(self):
#     def __init__(self, cache=None, **kwargs):
#     def do(self):
#     def __init__(self, update_cache=None, **kwargs):
#     def do(self):
#     def __init__(self, packages, **kwargs):
#     def do(self):
#     def __init__(self, packages=None, debconf=None,
#                  debian_frontend='noninteractive', **kwargs):
#     def do(self):
#     def __init__(self, selections=None, **kwargs):
#     def do(self):
#     def __init__(self, packages=None, debconf=None,
#                  debian_frontend='noninteractive', debian_priority=None,
#                  update_cache=None, install_recommends=False, **kwargs):
#     def get_packages_list(self, packages):
#     def do(self):
#     def diff(self):
# class source(Task):
# class update(Task):
# class list(Task):
# class search(Task):
# class upgrade(Task):
# class debconf_set_selections(Task):
# class install(Task):
# 
# Path: nuka/tasks/git.py
# class git(Task):
#     """git clone/fetch"""
# 
#     def __init__(self, src=None, dst=None,
#                  branch=None, tag=None, **kwargs):
#         kwargs.setdefault('name', src)
#         kwargs.update(src=src, dst=dst, branch=branch, tag=tag)
#         super(git, self).__init__(**kwargs)
# 
#     def pre_process(self):
#         if self.args['branch'] and self.args['tag']:
#             raise RuntimeError('Do not use both tag and branch')
#         if self.args['branch'] is None and self.args['tag'] is None:
#             self.args['branch'] = 'master'
#         if self.args['tag']:
#             self.args['depth'] = 1
# 
#     def current_ref(self):
#         ref = self.sh(['git', 'rev-parse', 'HEAD'], check=False)
#         if ref['rc'] == 0:
#             ref = ref['stdout'].strip()
#             return ref
# 
#     def do(self):
#         src = self.args['src']
#         dst = self.args['dst']
#         branch = self.args['branch']
#         tag = self.args['tag']
#         ref = branch or tag
#         cmd = ['git']
#         if os.path.isdir(dst):
#             old_ref = self.current_ref()
#             os.chdir(dst)
#             cmd.append('fetch')
#             if tag:
#                 cmd.append('--depth=1')
#             cmd.extend([src, ref])
#         else:
#             old_ref = None
#             cmd += ['clone']
#             if tag:
#                 cmd.extend([
#                     '--depth=1', '--single-branch',
#                     '-b', tag, '--depth=1'])
#             cmd.extend([src, dst])
#         log.info(cmd)
#         self.sh(cmd)
#         os.chdir(dst)
#         if tag:
#             self.sh(['git',  'fetch', '--tags'])
#         res = self.sh(['git', 'checkout',  ref])
#         res['changed'] = old_ref != self.current_ref()
#         return res


from nuka.tasks import apt
from nuka.tasks import git
import pytest
import os
# -*- coding: utf-8 -*-

pytestmark = [
    pytest.mark.skipif(
        'debian' not in os.environ['ENV_NAME'], reason='debian only'),
]


@pytest.mark.asyncio
async def test_clone(host):
    assert (await apt.install(packages=['git']))
    # FIXME: branch sucks on wheezy. maybe because an old git version
    # res = await git.git(
    #     src='https://github.com/gawel/aiocron.git',
    #     dst='/tmp/nuka_clone',
    # )
    # assert res

# Path: nuka/tasks/apt.py
# GPG_HEADER = b'-----BEGIN PGP PUBLIC KEY BLOCK-----'
# def apt_watcher(delay, fd):
#     def watcher(task, process):
#     def __init__(self, name=None, src=None, key=None, update=True, **kwargs):
#     def add_key(self, key):
#     def do(self):
#     def diff(self):
#     def __init__(self, cache=None, **kwargs):
#     def do(self):
#     def __init__(self, update_cache=None, **kwargs):
#     def do(self):
#     def __init__(self, packages, **kwargs):
#     def do(self):
#     def __init__(self, packages=None, debconf=None,
#                  debian_frontend='noninteractive', **kwargs):
#     def do(self):
#     def __init__(self, selections=None, **kwargs):
#     def do(self):
#     def __init__(self, packages=None, debconf=None,
#                  debian_frontend='noninteractive', debian_priority=None,
#                  update_cache=None, install_recommends=False, **kwargs):
#     def get_packages_list(self, packages):
#     def do(self):
#     def diff(self):
# class source(Task):
# class update(Task):
# class list(Task):
# class search(Task):
# class upgrade(Task):
# class debconf_set_selections(Task):
# class install(Task):
# 
# Path: nuka/tasks/git.py
# class git(Task):
#     """git clone/fetch"""
# 
#     def __init__(self, src=None, dst=None,
#                  branch=None, tag=None, **kwargs):
#         kwargs.setdefault('name', src)
#         kwargs.update(src=src, dst=dst, branch=branch, tag=tag)
#         super(git, self).__init__(**kwargs)
# 
#     def pre_process(self):
#         if self.args['branch'] and self.args['tag']:
#             raise RuntimeError('Do not use both tag and branch')
#         if self.args['branch'] is None and self.args['tag'] is None:
#             self.args['branch'] = 'master'
#         if self.args['tag']:
#             self.args['depth'] = 1
# 
#     def current_ref(self):
#         ref = self.sh(['git', 'rev-parse', 'HEAD'], check=False)
#         if ref['rc'] == 0:
#             ref = ref['stdout'].strip()
#             return ref
# 
#     def do(self):
#         src = self.args['src']
#         dst = self.args['dst']
#         branch = self.args['branch']
#         tag = self.args['tag']
#         ref = branch or tag
#         cmd = ['git']
#         if os.path.isdir(dst):
#             old_ref = self.current_ref()
#             os.chdir(dst)
#             cmd.append('fetch')
#             if tag:
#                 cmd.append('--depth=1')
#             cmd.extend([src, ref])
#         else:
#             old_ref = None
#             cmd += ['clone']
#             if tag:
#                 cmd.extend([
#                     '--depth=1', '--single-branch',
#                     '-b', tag, '--depth=1'])
#             cmd.extend([src, dst])
#         log.info(cmd)
#         self.sh(cmd)
#         os.chdir(dst)
#         if tag:
#             self.sh(['git',  'fetch', '--tags'])
#         res = self.sh(['git', 'checkout',  ref])
#         res['changed'] = old_ref != self.current_ref()
#         return res


# Path: tests/tasks/test_git.py
from nuka.tasks import apt
from nuka.tasks import git
import pytest
import os

# -*- coding: utf-8 -*-

pytestmark = [
    pytest.mark.skipif(
        'debian' not in os.environ['ENV_NAME'], reason='debian only'),
]


@pytest.mark.asyncio
async def test_clone(host):
    assert (await apt.install(packages=['git']))
    # FIXME: branch sucks on wheezy. maybe because an old git version
    # res = await git.git(
    #     src='https://github.com/gawel/aiocron.git',
    #     dst='/tmp/nuka_clone',
    # )
    # assert res

    res = await git.git(