# Path: nappingcat/contrib/git/exceptions.py
# class KittyGitRepoExists(NappingCatRejected):
#     def __init__(self, which):
#         super(KittyGitRepoExists, self).__init__("""
#             There's already a repo in %s. Whoops!
#         """.strip() % which)
# 
# class KittyGitUnauthorized(NappingCatRejected):
#     pass
# 
# class KittyGitBadParameter(NappingCatRejected):
#     pass
# 
# Path: nappingcat/exceptions.py
# class NappingCatException(Exception):
#     pass


import os
import sys
import subprocess
from nappingcat.contrib.git.exceptions import KittyGitRepoExists, KittyGitUnauthorized, KittyGitBadParameter
from nappingcat.exceptions import NappingCatException
def fork_repository(git, stdin, stdout, stderr, from_directory, to_directory):
    from_directory = os.path.abspath(from_directory)
    to_directory = os.path.abspath(to_directory)

    if not os.path.isdir(from_directory):
        raise NappingCatException("'%s' is not a valid repository." % from_directory)

    if os.path.isdir(to_directory):
        raise KittyGitRepoExists(to_directory)
    os.makedirs(to_directory)
    args = [
        git, '--git-dir=.', 'clone', '--mirror', from_directory, './'
    ]
    return 0 == subprocess.call(
        args=args,
        cwd=to_directory,
        stdin=stdin,
        stdout=stdout,
        stderr=stderr,
        close_fds=True,
    )

def create_repository(git, stdin, stdout, stderr, directory, template_dir=None, bare=True):
    if os.path.isdir(directory):

# Path: nappingcat/contrib/git/exceptions.py
# class KittyGitRepoExists(NappingCatRejected):
#     def __init__(self, which):
#         super(KittyGitRepoExists, self).__init__("""
#             There's already a repo in %s. Whoops!
#         """.strip() % which)
# 
# class KittyGitUnauthorized(NappingCatRejected):
#     pass
# 
# class KittyGitBadParameter(NappingCatRejected):
#     pass
# 
# Path: nappingcat/exceptions.py
# class NappingCatException(Exception):
#     pass


# Path: nappingcat/contrib/git/operations.py
import os
import sys
import subprocess
from nappingcat.contrib.git.exceptions import KittyGitRepoExists, KittyGitUnauthorized, KittyGitBadParameter
from nappingcat.exceptions import NappingCatException

def fork_repository(git, stdin, stdout, stderr, from_directory, to_directory):
    from_directory = os.path.abspath(from_directory)
    to_directory = os.path.abspath(to_directory)

    if not os.path.isdir(from_directory):
        raise NappingCatException("'%s' is not a valid repository." % from_directory)

    if os.path.isdir(to_directory):
        raise KittyGitRepoExists(to_directory)
    os.makedirs(to_directory)
    args = [
        git, '--git-dir=.', 'clone', '--mirror', from_directory, './'
    ]
    return 0 == subprocess.call(
        args=args,
        cwd=to_directory,
        stdin=stdin,
        stdout=stdout,
        stderr=stderr,
        close_fds=True,
    )

def create_repository(git, stdin, stdout, stderr, directory, template_dir=None, bare=True):
    if os.path.isdir(directory):

        raise KittyGitRepoExists(directory)