Skip to content

Commit 5ec52be

Browse files
committed
fix: retarget GitHub PR base on mount
When `git-stack mount` moves a branch to a new parent, update the associated GitHub PR's base branch to match, preventing `sync` from reverting the mount.
1 parent c0da384 commit 5ec52be

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/main.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,35 @@ fn inner_main() -> Result<()> {
357357
)
358358
}
359359
Some(Command::Mount { parent_branch }) => {
360-
state.mount(&git_repo, &repo, &current_branch, parent_branch)
360+
state.mount(&git_repo, &repo, &current_branch, parent_branch.clone())?;
361+
362+
// If this branch has a PR, retarget its base to the new parent
363+
let effective_parent =
364+
parent_branch.or_else(|| git::git_trunk(&git_repo).map(|t| t.main_branch));
365+
if let Some(parent) = effective_parent
366+
&& let Some(branch) = state.get_tree_branch(&repo, &current_branch)
367+
&& let Some(pr_number) = branch.pr_number
368+
&& let Ok(repo_id) = github::get_repo_identifier(&git_repo)
369+
&& let Ok(client) = github::GitHubClient::from_env(&repo_id)
370+
{
371+
match client.update_pr(
372+
&repo_id,
373+
pr_number,
374+
github::UpdatePrRequest {
375+
base: Some(&parent),
376+
title: None,
377+
body: None,
378+
},
379+
) {
380+
Ok(_) => {
381+
println!("Retargeted PR #{} base to '{}'.", pr_number, parent);
382+
}
383+
Err(e) => {
384+
tracing::warn!("Failed to retarget PR #{pr_number}: {e}");
385+
}
386+
}
387+
}
388+
Ok(())
361389
}
362390
Some(Command::Status { fetch }) => {
363391
state.try_auto_mount(&git_repo, &repo, &current_branch)?;

0 commit comments

Comments
 (0)