Beispiel #1
0
    def work(self, namespace: argparse.Namespace, constants: Constants, state: State):
        if has_collisions_with_service_files(constants):
            return

        Path.mkdir(constants.mygit_path)
        Path.mkdir(constants.mygit_objects_path)
        Path.mkdir(constants.mygit_refs_path)
        Path.mkdir(constants.mygit_branches_path)
        Path.mkdir(constants.mygit_index_dir_path)
        default_branch_name = "master"
        with Path.open(constants.mygit_head_path, "w") as head:
            head.write(default_branch_name)

        Path.open(constants.mygit_branches_path / default_branch_name, 'w').close()
        Path.open(constants.mygit_index_path, "w").close()
        Path.open(constants.mygit_log_path, "w").close()

        with Path.open(constants.mygit_ignore_path, "w") as ignore:
            ignore.write(".mygit")

        index_object(constants.mygit_ignore_path, constants, state)
        state.load_cache(
            constants,
            get_compressed_file_content(constants.mygit_index_path),
            get_last_commit_index_content(constants))

        make_commit("init", constants, state)
        logging.info(Fore.GREEN + "new repository is created")
Beispiel #2
0
def get_current_state(c: Constants) -> State:
    state = State()
    state.load_cache(
        c,
        backend.get_compressed_file_content(c.mygit_index_path),
        backend.get_last_commit_index_content(c))

    backend.check_status(c, state)

    return state
Beispiel #3
0
def handle_command(commands: dict, namespace: argparse.Namespace,
                   constants: Constants, state: State):
    state.load_cache(constants,
                     get_compressed_file_content(constants.mygit_index_path),
                     get_last_commit_index_content(constants))

    if namespace.command == "init":
        logging.warning(Fore.YELLOW +
                        "directory already contains the repository")
    else:
        commands[namespace.command].work(namespace, constants, state)