Skip to content

Commit

Permalink
fix: release squashed release PRs from main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoIeni committed Oct 25, 2024
1 parent e350da7 commit 7329ab8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 10 additions & 0 deletions crates/git_cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ impl Repo {
.context("cannot determine if git tag exists")?;
Ok(output.lines().count() >= 1)
}

pub fn get_branches_of_commit(&self, commit_hash: &str) -> anyhow::Result<Vec<String>> {
let output = self.git(&["branch", "--contains", commit_hash])?;
let branches = output
.lines()
.filter_map(|l| l.split_whitespace().last())
.map(|s| s.to_string())
.collect();
Ok(branches)
}
}

pub fn is_file_ignored(repo_path: &Utf8Path, file: &Utf8Path) -> bool {
Expand Down
18 changes: 16 additions & 2 deletions crates/release_plz_core/src/command/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,22 @@ async fn should_release(
// Get the last commit of the PR, i.e. the last commit that was pushed before the PR was merged
match pr_commits.last() {
Some(commit) if commit.sha != last_commit => {
// I need to checkout the last commit of the PR if it exists
Ok(ShouldRelease::YesWithCommit(commit.sha.clone()))
let is_pr_commit_in_original_branch = {
let branches_of_commit = repo.get_branches_of_commit(&commit.sha);
if let Ok(branches) = branches_of_commit {
branches.contains(&repo.original_branch().to_string())
} else {
false
}
};

if is_pr_commit_in_original_branch {
// I need to checkout the last commit of the PR if it exists
Ok(ShouldRelease::YesWithCommit(commit.sha.clone()))
} else {
// The commit is not in the original branch, probably the PR was squashed
Ok(ShouldRelease::Yes)
}
}
_ => {
// I'm already at the right commit
Expand Down

0 comments on commit 7329ab8

Please sign in to comment.