nickderobertis/flexlate

restructure the current path logic into _add_operation_via_branches

Closed this issue · 1 comments

restructure the current path logic into _add_operation_via_branches

as it will also be needed for other operations.

Commit changes for local and project

or os.getcwd will throw a FileNotExistsError (which also breaks path.absolute())

# TODO: restructure the current path logic into _add_operation_via_branches

                out_root=expanded_out_root,
            )
        else:
            # TODO: restructure the current path logic into _add_operation_via_branches
            #  as it will also be needed for other operations.
            # Commit changes for local and project
            cwd = Path(os.getcwd())
            absolute_out_root = out_root.absolute()
            def make_dirs_add_applied_template():
                # Need to ensure that both cwd and out root exist on the template branch
                for p in [cwd, absolute_out_root]:
                    if not p.exists():
                        p.mkdir(parents=True)
                # If cwd was deleted when switching branches, need to navigate back there
                # or os.getcwd will throw a FileNotExistsError (which also breaks path.absolute())
                os.chdir(cwd)

                config_manager.add_applied_template(
                    template,
                    config_path,
                    data=data,
                    project_root=project_root,
                    out_root=expanded_out_root,
                )

            _add_operation_via_branches(
                make_dirs_add_applied_template,
                repo,
                _add_template_commit_message(
                    template, out_root, Path(repo.working_dir)

2289cc96ea4bf20fbc193289a97fa0e79fc2e2bd