From d267ba3cf98fa722c0456e97bafd5a88f288d376 Mon Sep 17 00:00:00 2001 From: Charles Short Date: Wed, 16 Aug 2023 14:12:50 -0400 Subject: [PATCH] Improve ostree commit messages Allow the user to configure the commit message when performing an ostree commit. Testing PASSED Run apt-ostree compose create --repo /home/repo \ --base config/debian/bookworm test-repo PASSED Run ostree log --repo /home/repo test-repo and look at the output of log file. PASSED Run apt-ostree compose create --edit --repo /home/repo \ --base config/debian/bookworm test-2 PASSED Run ostree log --repo /home/repo test-repo and look at the output of log file. Story: 2010867 Task: 48556 Change-Id: Iee14930c75aa6468783398e3c5f63000cf52a520 Signed-off-by: Charles Short --- apt_ostree/cmd/compose/create.py | 7 +++++-- apt_ostree/cmd/options.py | 14 ++++++++++++++ apt_ostree/ostree.py | 30 +++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 11 deletions(-) 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}.")