Ejemplo n.º 1
0
    def test_direct_root(self):
        setup_py = self.temp_path / 'setup.py'
        setup_py.touch()

        root_path = get_project_root_path(self.temp_path)

        self.assertEqual(root_path, self.temp_path)
Ejemplo n.º 2
0
    def __exit__(self, exc_type, exc_value, traceback):
        if not self.partially_staged:
            return

        if exc_type is not None:
            # an error has occurred
            # restore working tree and index as it was before formatting
            self.restore_working_tree()
            _read_tree(self.index)
        else:
            # save formatting changes
            formatted_tree = _write_tree()

            self.restore_working_tree()

            # restore index
            # formatted_tree will be the same as index if no changes are applied
            _read_tree(formatted_tree)

            if formatted_tree != self.index:
                # create diff between index and formatted_tree
                patch = _get_tree_diff(self.index, formatted_tree)
                try:
                    # apply diff to working tree
                    _apply_diff(patch)
                except GitError as e:
                    print(
                        'Found conflicts between plugin and local changes. '
                        'Plugin changes will be ignored for conflicted hunks.',
                        e,
                    )

                    rootpath = get_project_root_path()
                    for path in rootpath.glob('*.rej'):
                        path.unlink()
Ejemplo n.º 3
0
    def test_with_sub_directory(self):
        sub_path = self.temp_path / 'foo'
        sub_path.mkdir()
        setup_py = self.temp_path / 'setup.py'
        setup_py.touch()

        root_path = get_project_root_path(sub_path)

        self.assertEqual(root_path, self.temp_path)
Ejemplo n.º 4
0
    def test_with_env_pwd(self):
        setup_py = self.temp_path / 'setup.py'
        setup_py.touch()
        sub_path = self.temp_path / 'foo'
        sub_path.mkdir()

        os.environ['PWD'] = str(sub_path)

        root_path = get_project_root_path()

        self.assertEqual(root_path, self.temp_path)
Ejemplo n.º 5
0
    def test_without_project_root(self):
        root_path = get_project_root_path(self.temp_path)

        self.assertEqual(root_path, self.temp_path)