use crate::worktree::WorktreeInfo;
use super::pr_helpers::{create_github_pr, push_branch};
pub(super) async fn push_and_create_pr(
wt: &WorktreeInfo,
base_branch: Option<&str>,
prompt: Option<&str>,
) -> anyhow::Result<String> {
stage_and_commit(wt).await;
push_branch(wt).await?;
create_github_pr(wt, base_branch, prompt).await
}
async fn stage_and_commit(wt: &WorktreeInfo) {
let diff_check = tokio::process::Command::new("git")
.args(["diff", "--quiet", "HEAD"])
.current_dir(&wt.path)
.status()
.await;
if diff_check.map(|s| !s.success()).unwrap_or(true) {
let _ = tokio::process::Command::new("git")
.args(["add", "-A"])
.current_dir(&wt.path)
.output()
.await;
let _ = tokio::process::Command::new("git")
.args([
"commit",
"-m",
&format!("codetether: TUI agent work ({})", wt.name),
])
.current_dir(&wt.path)
.output()
.await;
}
}