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 <charles.short@windriver.com>
This commit is contained in:
Charles Short 2023-08-16 14:12:50 -04:00 committed by Chuck Short
parent 2d3ff906a3
commit d267ba3cf9
3 changed files with 40 additions and 11 deletions

View File

@ -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")

View File

@ -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

View File

@ -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}.")