# Path: wikked/scm/base.py
# class SourceControl(object):
#     def __init__(self):
#         pass
# 
#     def start(self, wiki):
#         pass
# 
#     def init(self, wiki):
#         pass
# 
#     def postInit(self):
#         pass
# 
#     def getSpecialFilenames(self):
#         raise NotImplementedError()
# 
#     def getHistory(self, path=None, limit=10, after_rev=None):
#         raise NotImplementedError()
# 
#     def getState(self, path):
#         raise NotImplementedError()
# 
#     def getRevision(self, path, rev):
#         raise NotImplementedError()
# 
#     def diff(self, path, rev1, rev2):
#         raise NotImplementedError()
# 
#     def commit(self, paths, op_meta):
#         pass
# 
#     def revert(self, paths=None):
#         pass
# 
# STATE_NEW = 2
# 
# STATE_MODIFIED = 1
# 
# STATE_COMMITTED = 0


import os
import os.path
import logging
import subprocess
    import pygit2
from .base import (
        SourceControl,
        STATE_NEW, STATE_MODIFIED, STATE_COMMITTED)

    def getSpecialFilenames(self):
        specials = ['.git', '.gitignore']
        return [os.path.join(self.root, d) for d in specials]

    def getState(self, path):
        return self._status(path)

    def _run(self, cmd, *args, **kwargs):
        exe = [self.git]
        if 'norepo' not in kwargs or not kwargs['norepo']:
            exe.append('--git-dir="%s"' % self.root)
        exe.append(cmd)
        exe += args
        logger.debug("Running Git: " + str(exe))
        return subprocess.check_output(exe)


class GitLibSourceControl(GitBaseSourceControl):
    def __init__(self, root):
        if not SUPPORTS_GIT:
            raise Exception(
                    "Can't support Git because pygit2 is not available.")
        GitBaseSourceControl.__init__(self, root)

    def initRepo(self, wiki):
        GitBaseSourceControl.initRepo(self, wiki)
        self.repo = pygit2.Repository(self.root)

    def _initRepo(self, path):

# Path: wikked/scm/base.py
# class SourceControl(object):
#     def __init__(self):
#         pass
# 
#     def start(self, wiki):
#         pass
# 
#     def init(self, wiki):
#         pass
# 
#     def postInit(self):
#         pass
# 
#     def getSpecialFilenames(self):
#         raise NotImplementedError()
# 
#     def getHistory(self, path=None, limit=10, after_rev=None):
#         raise NotImplementedError()
# 
#     def getState(self, path):
#         raise NotImplementedError()
# 
#     def getRevision(self, path, rev):
#         raise NotImplementedError()
# 
#     def diff(self, path, rev1, rev2):
#         raise NotImplementedError()
# 
#     def commit(self, paths, op_meta):
#         pass
# 
#     def revert(self, paths=None):
#         pass
# 
# STATE_NEW = 2
# 
# STATE_MODIFIED = 1
# 
# STATE_COMMITTED = 0


# Path: wikked/scm/git.py
import os
import os.path
import logging
import subprocess
    import pygit2
from .base import (
        SourceControl,
        STATE_NEW, STATE_MODIFIED, STATE_COMMITTED)


    def getSpecialFilenames(self):
        specials = ['.git', '.gitignore']
        return [os.path.join(self.root, d) for d in specials]

    def getState(self, path):
        return self._status(path)

    def _run(self, cmd, *args, **kwargs):
        exe = [self.git]
        if 'norepo' not in kwargs or not kwargs['norepo']:
            exe.append('--git-dir="%s"' % self.root)
        exe.append(cmd)
        exe += args
        logger.debug("Running Git: " + str(exe))
        return subprocess.check_output(exe)


class GitLibSourceControl(GitBaseSourceControl):
    def __init__(self, root):
        if not SUPPORTS_GIT:
            raise Exception(
                    "Can't support Git because pygit2 is not available.")
        GitBaseSourceControl.__init__(self, root)

    def initRepo(self, wiki):
        GitBaseSourceControl.initRepo(self, wiki)
        self.repo = pygit2.Repository(self.root)

    def _initRepo(self, path):

        pygit2.init_repository(path, False)