Merge "Improve ostree commit messages"

This commit is contained in:
Zuul 2023-08-18 18:56:50 +00:00 committed by Gerrit Code Review
commit b25c2f5150
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}.")