diff --git a/apt_ostree/cmd/compose/create.py b/apt_ostree/cmd/compose/create.py index 9cdb791..d210cbb 100644 --- a/apt_ostree/cmd/compose/create.py +++ b/apt_ostree/cmd/compose/create.py @@ -22,7 +22,7 @@ from apt_ostree.utils import run_command @click.command(short_help="Create treefile") @pass_state_context @compose_options -def create(state, repo, base, branch): +def create(state, repo, base, branch, edit): if state.repo is None: click.secho("You did not supply an ostree repository", fg="red") sys.exit(1) @@ -77,4 +77,7 @@ def create(state, repo, base, branch): "--output", str(workdir)], cwd=state.base) create_ostree(rootfs) - ostree_commit(state.repo, state.branch, rootfs) + ostree_commit(state, + rootfs, + subject="Commit by apt-ostree", + msg="Initialized by apt-ostree") diff --git a/apt_ostree/cmd/options.py b/apt_ostree/cmd/options.py index 18446b1..74f77d7 100644 --- a/apt_ostree/cmd/options.py +++ b/apt_ostree/cmd/options.py @@ -40,6 +40,19 @@ def workspace_option(f): )(f) +def edit_option(f): + def callback(ctxt, param, value): + state = ctxt.ensure_object(State) + state.edit = value + return value + return click.option( + "--edit", + is_flag=True, + help="Increase verbosity", + callback=callback + )(f) + + def repo_option(f): """ostree repo path option""" def callback(ctxt, param, value): @@ -87,4 +100,5 @@ def compose_options(f): f = repo_option(f) f = base_option(f) f = branch_option(f) + f = edit_option(f) return f diff --git a/apt_ostree/ostree.py b/apt_ostree/ostree.py index 7935070..a05e016 100644 --- a/apt_ostree/ostree.py +++ b/apt_ostree/ostree.py @@ -12,15 +12,27 @@ from apt_ostree.log import log_step from apt_ostree.utils import run_command -def ostree_commit(repo, branch, rootfs): - """Commit directory to ostree repository""" - with complete_step(f"Committing {branch} to {repo}"): - r = run_command( - ["ostree", "commit", f"--repo={repo}", - f"--branch={branch}", str(rootfs)], - ) +def ostree_commit(state, + rootfs, + subject=None, + msg=None): + """Commit rootfs to ostree repository.""" + cmd = ["ostree", "commit", f"--repo={state.repo}"] + if state.edit: + cmd += ["-e"] + else: + if subject: + cmd += [f"--subject={subject}"] + if msg: + cmd += [f"--body={msg}"] + + cmd += [f"--branch={state.branch}", str(rootfs)] + with complete_step(f"Committing {state.branch} to {state.repo}"): + r = run_command(cmd) if r.returncode != 0: - click.secho(f"Failed to commit to ostree.", fg="red") + click.secho( + f"Failed to commit {state.branch} to {state.repo}.", + fg="red") raise - log_step(f"Succesfully commited {branch} to {repo}.") + log_step(f"Succesfully commited {state.branch} to {state.repo}.")