Exemple #1
0
    def test_update(self):
        gitignore = CachedIgnore()
        gitignore.cache = {"some_key": "some_value"}

        gitignore.update()

        assert gitignore.cache == {}
Exemple #2
0
    def test_update(self):
        gitignore = CachedIgnore()
        gitignore.cache = {"some_key": "some_value"}

        gitignore.update()

        assert gitignore.cache == {}
Exemple #3
0
    def __init__(self,
                 remote_url,
                 repo_path,
                 mount_path,
                 credentials,
                 current_path="current",
                 history_path="history",
                 branch=None,
                 user="******",
                 group="root",
                 **kwargs):
        """
        Clone repo from a remote into repo_path/<repo_name> and checkout to
        a specific branch.

        :param str remote_url: URL of the repository to clone
        :param str repo_path: Where are all the repos are cloned
        :param str branch: Branch to checkout after the
            clone. The default is to use the remote's default branch.

        """

        self.remote_url = remote_url
        self.repo_path = repo_path
        self.mount_path = mount_path
        self.current_path = current_path
        self.history_path = history_path
        self.branch = branch

        self.routes = []

        log.info('Cloning into {}'.format(self.repo_path))

        self.repo = Repository.clone(self.remote_url, self.repo_path,
                                     self.branch, credentials)
        log.info('Done cloning')

        self.repo.credentials = credentials

        submodules = os.path.join(self.repo_path, '.gitmodules')
        ignore = os.path.join(self.repo_path, '.gitignore')
        self.repo.ignore = CachedIgnore(submodules=submodules,
                                        ignore=ignore,
                                        exclude=kwargs['ignore_file'] or None,
                                        hard_ignore=kwargs['hard_ignore'])

        self.uid = getpwnam(user).pw_uid
        self.gid = getgrnam(group).gr_gid

        self.commit_queue = kwargs['commit_queue']
        self.mount_time = int(time.time())

        self.max_size = kwargs['max_size']
        self.max_offset = kwargs['max_offset']

        try:
            self.repo.commits.update()
        except Exception, e:
            log.error("[Exception] repo.commits.update failed: %s", str(e))
            sys.exit()
Exemple #4
0
    def __init__(self,
                 remote_url,
                 repo_path,
                 mount_path,
                 credentials,
                 current_path="current",
                 history_path="history",
                 branch=None,
                 user="******",
                 group="root",
                 **kwargs):
        """
        Clone repo from a remote into repo_path/<repo_name> and checkout to
        a specific branch.

        :param str remote_url: URL of the repository to clone
        :param str repo_path: Where are all the repos are cloned
        :param str branch: Branch to checkout after the
            clone. The default is to use the remote's default branch.

        """

        self.remote_url = remote_url
        self.repo_path = repo_path
        self.mount_path = mount_path
        self.current_path = current_path
        self.history_path = history_path
        self.branch = branch

        self.routes = []

        log.info("Cloning into {}".format(self.repo_path))

        self.repo = Repository.clone(self.remote_url, self.repo_path,
                                     self.branch, credentials)
        log.info("Done cloning")

        self.repo.credentials = credentials

        submodules = os.path.join(self.repo_path, ".gitmodules")
        ignore = os.path.join(self.repo_path, ".gitignore")
        self.repo.ignore = CachedIgnore(
            submodules=submodules,
            ignore=ignore,
            exclude=kwargs["ignore_file"] or None,
            hard_ignore=kwargs["hard_ignore"],
        )

        self.uid = getpwnam(user).pw_uid
        self.gid = getgrnam(group).gr_gid

        self.commit_queue = kwargs["commit_queue"]
        self.mount_time = int(time.time())

        self.max_size = kwargs["max_size"]
        self.max_offset = kwargs["max_offset"]

        self.repo.commits.update()

        self.workers = []
Exemple #5
0
    def test_init(self):
        mocked_os = MagicMock()
        mocked_os.path.exists.return_value = True
        mocked_re = MagicMock()
        mocked_re.findall.return_value = [[None, None, "found"]]

        with patch("gitfs.cache.gitignore.open", create=True) as mocked_open:
            mocked_file = mocked_open.return_value.__enter__.return_value
            mocked_file.read.return_value = "file"

            with patch.multiple("gitfs.cache.gitignore",
                                os=mocked_os,
                                re=mocked_re):
                gitignore = CachedIgnore("some_file", "some_file")

                assert gitignore.items == [
                    ".git",
                    ".git/*",
                    "/.git/*",
                    "*.keep",
                    "*.gitmodules",
                    "/found/*",
                    "/found",
                    "found",
                ]
Exemple #6
0
    def test_decorator(self):
        mocked_function = MagicMock()
        mocked_function.__name__ = "function"
        mocked_object = MagicMock()
        mocked_object.ignore = CachedIgnore()
        mocked_inspect = MagicMock()
        mocked_inspect.getargspec.return_value = [["file"]]

        with patch.multiple("gitfs.utils.decorators.not_in",
                            inspect=mocked_inspect):
            not_in("ignore", check=["file"])(mocked_function)(mocked_object,
                                                              "file")

        mocked_function.assert_called_once_with(mocked_object, "file")
Exemple #7
0
    def test_contains(self):
        gitignore = CachedIgnore()

        assert '.git' in gitignore
        assert 'file' not in gitignore
Exemple #8
0
    def test_contains(self):
        gitignore = CachedIgnore()

        assert ".git" in gitignore
        assert "file" not in gitignore