Exemplo 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)
Exemplo n.º 2
0
def initialize_repository_at(path: Path):
    if path.isdir(CONFIG_DIR):
        shutil.rmtree(path.combine(CONFIG_DIR))

    path.mkdir(COMMITS_DIR)
    path.mkdir(BRANCHES_DIR)
    path.mkdir(STORAGE_PATH)

    provider = Provider(path)
    commit = Commit(
        About(Author('N\\A', 'N\\A'), datetime.datetime.now(),
              'lgit auto initialization commit'), 0, -1, {})
    master = Branch('master', 0)
    provider.save_new(commit)
    provider.save_new(master)
    provider.set_current_branch('master')
Exemplo 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

        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()