예제 #1
0
class Repository:
    path = None
    adapter = None

    scm_dirs = [".git"]

    def __init__(self, path):
        if not os.path.exists(path) or not os.path.isdir(path):
            raise RepositoryPathInvalid("Path doesn't exists or isn't a directory (%s)\n" % path)

        try:
            scm = (set(self.scm_dirs) & set(os.listdir(path))).pop()
        except KeyError:
            raise RepositoryAdapterNotFound("Can't define repository type")
        else:
            self.path = path
            if scm == ".git":
                self.adapter = Git(path)

    def get_scm(self):
        """Get scm used as string."""
        if self.adapter is None:
            return None
        return self.adapter.__class__.__name__

    def status(self):
        return self.adapter.status()

    def update(self):
        return self.adapter.update()
예제 #2
0
def clone(url, path):
    """Clone a repository."""
    adapter = None
    if url[:4] == "git@" or url[-4:] == ".git":
        adapter = Git(path)

    if adapter is None:
        raise RepositoryAdapterNotFound("Can't find adapter for `%s` repository url" % url)

    adapter.clone(url)
예제 #3
0
파일: git_test.py 프로젝트: hackolite/yoda
    def setUp(self):
        """Set up git adapter and sandbox."""
        self.sandbox = Sandbox()
        self.sandbox.mkdir("repo")

        self.git = Git(os.path.join(self.sandbox.path, "repo"))
        self.git.execute = Mock(return_value=None)
예제 #4
0
파일: repository.py 프로젝트: Numergy/yoda
def clone(url, path):
    """Clone a repository."""
    adapter = None
    if url[:4] == "git@" or url[-4:] == ".git":
        adapter = Git(path)
    if url[:6] == "svn://":
        adapter = Svn(path)
    if url[:6] == "bzr://":
        adapter = Bzr(path)
    if url[:9] == "ssh://hg@":
        adapter = Hg(path)

    if adapter is None:
        raise RepositoryAdapterNotFound(
            "Can't find adapter for `%s` repository url" % url)

    return adapter.clone(url)
예제 #5
0
    def __init__(self, path):
        if not os.path.exists(path) or not os.path.isdir(path):
            raise RepositoryPathInvalid("Path doesn't exists or isn't a directory (%s)\n" % path)

        try:
            scm = (set(self.scm_dirs) & set(os.listdir(path))).pop()
        except KeyError:
            raise RepositoryAdapterNotFound("Can't define repository type")
        else:
            self.path = path
            if scm == ".git":
                self.adapter = Git(path)
예제 #6
0
파일: git_test.py 프로젝트: hackolite/yoda
class TestGit(unittest.TestCase):
    """Git adapter test suite."""
    sandbox = None
    git = None

    def setUp(self):
        """Set up git adapter and sandbox."""
        self.sandbox = Sandbox()
        self.sandbox.mkdir("repo")

        self.git = Git(os.path.join(self.sandbox.path, "repo"))
        self.git.execute = Mock(return_value=None)

    def tearDown(self):
        """Unset test object."""
        self.sandbox.destroy()
        self.git = None

    def test_status(self):
        """Test git status."""
        self.git.status()
        self.git.execute.assert_called_once_with(
            "git status",
            os.path.join(self.sandbox.path, "repo"))

    def test_update(self):
        """Test git update."""
        self.git.update()
        self.git.execute.assert_called_once_with(
            "git pull --rebase",
            os.path.join(self.sandbox.path, "repo"))

    def test_clone(self):
        """Test git status."""
        self.git.clone("[email protected]:foo/bar")
        self.git.execute.assert_called_once_with(
            "git clone %s %s" % (
                "[email protected]:foo/bar",
                os.path.join(self.sandbox.path, "repo")))