Ejemplo n.º 1
0
    def execute(self, args, path: Path):
        if not contains_repository_at(path):
            print(f'There is no repository at {path.root}')
            return

        name, email, comment, id_ = _parse_args(args)
        provider = Provider(path)

        if not provider.is_commit(id_):
            print(f'{id_} is not commit')
            return

        commit = provider.get_commit(id_)

        if name is not None:
            commit.set_author_name(name)

        if email is not None:
            commit.set_author_email(email)

        if comment is not None:
            commit.set_comment(comment)

        provider.save_new(commit)

        print(f'Commit was changed to:')
        print(commit.description_string)
Ejemplo n.º 2
0
    def execute(self, args, path: Path):
        name = _parse_args(args)

        if not contains_repository_at(path):
            print(f'{path.root} doesnt have repository')

        provider = Provider(path)

        if not provider.is_branch(name):
            print(f'Repository doesnt have branch \'{name}\'')
            return

        if isinstance(provider.get_branch(name), Tag):
            print('Cant checkout to tag')
            return

        if provider.get_current_branch().name == name:
            print(f'Already at {name}')
            return

        provider.set_current_branch(name)
        print(f'Current branch for repository was switched to \'{name}\'')

        performer = Performer(path, StorageController(path))
        performer.perform_commit(provider.get_current_commit())

        stage = StageController(path)
        stage.clear()
        stage.write()
Ejemplo n.º 3
0
    def execute(self, args, path: Path):
        if not contains_repository_at(path):
            print(f'There is no repository at {path.root}')
            return

        repo = Repository(path)
        branch = repo.provider.get_current_branch()
        current_commit = repo.provider.get_commit(branch.commit_id)
        differ = Differ()

        print(f'Repository at branch: {branch.name}')
        file_to_status = differ.get_changes_from_commit(
            current_commit, repo.storage_controller, repo.path)

        if set(file_to_status.values()) == {State.NOT_CHANGED}:
            print('No any changes in repository')
            return

        def print_for_state(st, intro):
            e = list(
                map(lambda p: p[0],
                    filter(lambda p: p[1] == st, file_to_status.items())))

            if len(e) == 0:
                return

            print(
                f'{intro}:{os.linesep}{f"{os.linesep}".join(map(lambda x: " " + x, e))}'
            )

        print_for_state(State.NEW, 'New files')
        print_for_state(State.DELETED, 'Deleted files')
        print_for_state(State.MODIFIED, 'Modified files')
Ejemplo n.º 4
0
    def execute(self, args, path: Path):
        args = _parse_args(args)

        if contains_repository_at(path) and not args.strict:
            print(f'{path.root} already contains repository')
            return

        initialize_repository_at(path)

        print(f'Initialized empty repository at {path.root}')
Ejemplo n.º 5
0
Archivo: add.py Proyecto: rkhapov/lgit
    def execute(self, args, path: Path):
        args = _parse_args(args)

        if not contains_repository_at(path):
            print(f'No repository at {path.root}')
            return

        con = StageController(path)

        for file in args.file:
            if not path.exists(file):
                print(f'No that file or directory: {file}')

            con.add(file, report=True)

        con.write()
Ejemplo n.º 6
0
Archivo: show.py Proyecto: rkhapov/lgit
    def execute(self, args, path: Path):
        if not contains_repository_at(path):
            print(f'{path.root} does not contains repository')
            return

        provider = Provider(path)

        args = _parse_args(args)
        branch = args.branch if args.branch != '' else provider.get_current_branch(
        ).name

        if not provider.is_branch(branch):
            print(f'No that branch: {branch}')
            return

        _print_description(branch, provider)
Ejemplo n.º 7
0
    def execute(self, args, path: Path):
        if not contains_repository_at(path):
            print(f'There is no repository at {path.root}')
            return

        src, dst, file = _parse_args(args)

        provider = Provider(path)
        storage = StorageController(path)

        if not provider.is_commit(src) or not provider.is_commit(dst):
            print('Invalid commit id')
            return

        differ = Differ()
        diffs = differ.get_commit_diffs(provider.get_commit(src),
                                        provider.get_commit(dst), storage)

        if file is not None:
            print(f'Diffs at file {file}:')

            for d in diffs:
                if path.relpath(d.name) != normpath(file):
                    continue

                if d.state == State.DELETED:
                    print('File was deleted')
                elif d.state == State.NOT_CHANGED:
                    print('File didnt changed')
                else:
                    d.print()
                break
        else:

            def print_(t, p, m):
                l = list(filter(lambda x: x.state == t, p))

                if len(l) == 0:
                    return

                print(m)
                for d in l:
                    print(d.name)

            print_(State.DELETED, diffs, 'Deleted files')
            print_(State.NEW, diffs, 'New files')
            print_(State.MODIFIED, diffs, 'Modified files')
Ejemplo n.º 8
0
    def execute(self, args, path: Path):
        if not contains_repository_at(path):
            print(f'There is no repository at {path.root}')
            return

        about = _parse_about(args)

        provider = Provider(path)
        storage = StorageController(path)
        stage = StageController(path)
        differ = Differ()
        branch = provider.get_current_branch()
        commit = provider.get_commit(branch.commit_id)

        if stage.is_empty():
            print('Nothing to commit: stage is empty')
            return

        changes = differ.get_changes_from_commit(commit, storage, path)
        file_to_id = {}

        for f, s in changes.items():
            if not stage.contains(f):
                continue

            if s == State.NOT_CHANGED:
                file_to_id[f] = commit.get_file_storage_name(f)
            elif s == State.NEW or s == State.MODIFIED:
                print(f'Commit {f}')
                file_to_id[f] = storage.save_file(f)
            # deleted files are not saved in commit

        id_ = provider.get_next_commit_id()

        new_commit = cm(about, id_, commit.id, file_to_id)
        branch.set_commit_id(id_)

        provider.save_new(new_commit)
        provider.save_new(branch)

        print(new_commit.description_string)

        stage.clear()
        stage.write()
Ejemplo n.º 9
0
    def execute(self, args, path: Path):
        if not contains_repository_at(path):
            print(f'There is not repository at {path.root}')
            return

        name, id_, all_ = _parse_args(args)
        provider = Provider(path)

        if all_:
            _print_all_branches(provider)
            return

        if id_ is None:
            _create_branch(name, provider)
        else:
            if not provider.is_commit(id_):
                print(f'No that commit: {id_}')
                return

            _move_branch(name, id_, provider)

            performer = Performer(path, StorageController(path))
            performer.perform_commit(provider.get_commit(id_))