Exemple #1
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()
Exemple #2
0
    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)
Exemple #3
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()