feat(webpage): add push subcommand with -f flag

新增 `mytoolkit webpage push <name>` 用于推送项目源码仓库,
支持 `-f/--force` 选项(内部使用 --force-with-lease)。
This commit is contained in:
Zhengshou Lai
2026-05-05 12:40:10 +08:00
parent 55af210db7
commit 92f8536604
2 changed files with 37 additions and 1 deletions
+36
View File
@@ -107,6 +107,42 @@ def webpage_build_serve(name, serve, port):
raise click.Abort()
@webpage_cmd.command("push")
@click.argument("name", type=click.Choice(_NAMES, case_sensitive=False))
@click.option(
"-f",
"--force",
is_flag=True,
help="Force push via --force-with-lease (refuses if upstream moved unexpectedly).",
)
@click.argument("push_args", nargs=-1)
def webpage_push(name, force, push_args):
"""Push the webpage project's source repo (`git push`).
Default pushes the current branch to its tracked upstream. Extra
arguments are forwarded to `git push` (e.g. `origin main`).
"""
svc = get_service(name)
assert svc.project_dir is not None
if not svc.project_dir.exists():
click.secho(f"Project directory not found: {svc.project_dir}", fg="red")
raise click.Abort()
cmd = ["git", "push"]
if force:
cmd.append("--force-with-lease")
if push_args:
cmd.extend(push_args)
click.secho(f"Pushing {svc.name} ({svc.description}) ...", fg="cyan")
proc = subprocess.run(cmd, cwd=svc.project_dir, env=no_color_env())
if proc.returncode != 0:
click.secho(f"Push failed for {svc.name} (exit {proc.returncode})", fg="red")
raise click.Abort()
click.secho(f"{svc.name} pushed.", fg="green")
@webpage_cmd.command("deploy")
@click.argument("name", type=click.Choice(_NAMES, case_sensitive=False))
@click.argument("deploy_args", nargs=-1)