summaryrefslogtreecommitdiff
path: root/makima/src/daemon/worktree
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-02-10 14:50:07 +0000
committersoryu <soryu@soryu.co>2026-02-10 14:50:07 +0000
commit15b6e5fba161a194fe5427d7d29b0c4286423260 (patch)
treefdd7bde229150cbb56d37714c23c2dc9db902f28 /makima/src/daemon/worktree
parent526edf672aae73c3670ab6141253bf92f1fbfe8c (diff)
downloadsoryu-15b6e5fba161a194fe5427d7d29b0c4286423260.tar.gz
soryu-15b6e5fba161a194fe5427d7d29b0c4286423260.zip
Add auto-PR creation for remote repos in directives
Diffstat (limited to 'makima/src/daemon/worktree')
-rw-r--r--makima/src/daemon/worktree/manager.rs92
1 files changed, 92 insertions, 0 deletions
diff --git a/makima/src/daemon/worktree/manager.rs b/makima/src/daemon/worktree/manager.rs
index 310627c..20c93b1 100644
--- a/makima/src/daemon/worktree/manager.rs
+++ b/makima/src/daemon/worktree/manager.rs
@@ -1417,6 +1417,98 @@ impl WorktreeManager {
Ok(())
}
+ /// Push a worktree branch to origin (the upstream GitHub remote).
+ /// Simpler than push_to_target_repo — just pushes to origin.
+ pub async fn push_branch_to_origin(
+ &self,
+ worktree_path: &Path,
+ branch_name: &str,
+ task_name: &str,
+ ) -> Result<(), WorktreeError> {
+ tracing::info!(
+ worktree = %worktree_path.display(),
+ branch = %branch_name,
+ "Pushing branch to origin"
+ );
+
+ // Stage all changes
+ let output = Command::new("git")
+ .args(["add", "-A"])
+ .current_dir(worktree_path)
+ .output()
+ .await?;
+
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ return Err(WorktreeError::GitCommand(format!(
+ "Failed to stage changes: {}",
+ stderr
+ )));
+ }
+
+ // Check if there are staged changes to commit
+ let output = Command::new("git")
+ .args(["diff", "--cached", "--quiet"])
+ .current_dir(worktree_path)
+ .output()
+ .await?;
+
+ // Exit code 1 means there are staged changes
+ if !output.status.success() {
+ tracing::info!("Committing staged changes before push to origin");
+
+ let commit_message = format!("feat: {}", task_name);
+ let output = Command::new("git")
+ .args(["commit", "-m", &commit_message])
+ .current_dir(worktree_path)
+ .output()
+ .await?;
+
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ return Err(WorktreeError::GitCommand(format!(
+ "Failed to commit changes: {}",
+ stderr
+ )));
+ }
+ }
+
+ // Ensure there are commits to push
+ let output = Command::new("git")
+ .args(["log", "--oneline", "-1"])
+ .current_dir(worktree_path)
+ .output()
+ .await?;
+
+ if !output.status.success() {
+ return Err(WorktreeError::GitCommand(
+ "No commits in worktree".to_string(),
+ ));
+ }
+
+ // Push to origin
+ let output = Command::new("git")
+ .args(["push", "-u", "origin", &format!("HEAD:{}", branch_name)])
+ .current_dir(worktree_path)
+ .output()
+ .await?;
+
+ if !output.status.success() {
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ return Err(WorktreeError::GitCommand(format!(
+ "Failed to push to origin: {}",
+ stderr
+ )));
+ }
+
+ tracing::info!(
+ branch = %branch_name,
+ "Branch pushed to origin successfully"
+ );
+
+ Ok(())
+ }
+
/// Merge a branch into the target branch in the target repository.
///
/// This pushes the branch first (if needed), then performs a merge in the target repo.