Skip to content

Commit

Permalink
After landing a Pull Request, delete the old branch on GitHub
Browse files Browse the repository at this point in the history
GitHub may do this automatically, if it's configured that way, but it doesn't hurt to just try do it. The exit code from 'git push' is ignored anyway.

Test Plan:
Land a PR with `spr land` in a repo that is not configured to automatically delete PR branches.

Reviewers: jozef-mokry

Reviewed By: jozef-mokry

Pull Request: #2
  • Loading branch information
Sven Over authored Feb 11, 2022
1 parent c1e5834 commit befc815
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/commands/land.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ pub async fn land(
return Err(merge.message.map(Error::new).unwrap_or(Error::empty()));
}

let mut remove_old_branch_child_process =
async_process::Command::new("git")
.arg("push")
.arg("--delete")
.arg("--")
.arg(&config.remote_name)
.arg(&pull_request.head)
.stdout(async_process::Stdio::null())
.stderr(async_process::Stdio::null())
.spawn()?;

// Rebase us on top of the now-landed commit
if let Some(sha) = merge.sha {
// Try this up to three times, because fetching the very moment after
Expand Down Expand Up @@ -202,5 +213,10 @@ pub async fn land(
))?;
}

// Wait for the "git push" to delete the old Pull Request branch to finish,
// but ignore the result. GitHub may be configured to delete the branch
// automatically, in which case it's gone already and this command fails.
remove_old_branch_child_process.status().await?;

Ok(())
}

0 comments on commit befc815

Please sign in to comment.