Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/monorepo/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn release(
return Ok(());
}

let branch = crate::git::resolve_current_branch(&open_repo(&root)?, &config.workspace.branch);
let mut last_err: Option<anyhow::Error> = None;
for attempt in 1..=MAX_RELEASE_REGENERATE_ATTEMPTS {
let pre_attempt_tags: std::collections::HashSet<String> = {
Expand Down Expand Up @@ -97,7 +98,7 @@ pub fn release(
if attempt < MAX_RELEASE_REGENERATE_ATTEMPTS
&& crate::git::is_push_rejected_error(&e) =>
{
warn_stale_attempt(attempt, &config, &e);
warn_stale_attempt(attempt, &branch, &e);

cleanup_failed_release_attempt(&root, &config, &pre_attempt_tags)?;
last_err = Some(e);
Expand Down Expand Up @@ -129,14 +130,13 @@ fn is_single_shot(config: &Config, dry_run: bool) -> bool {
)
}

fn warn_stale_attempt(attempt: usize, config: &Config, e: &anyhow::Error) {
fn warn_stale_attempt(attempt: usize, branch: &str, e: &anyhow::Error) {
tracing::warn!("");
tracing::warn!(
"{}",
format!(
"Release attempt {attempt}/{MAX_RELEASE_REGENERATE_ATTEMPTS} \
pushed onto a stale '{}': {e:#}",
config.workspace.branch,
pushed onto a stale '{branch}': {e:#}",
)
.yellow()
);
Expand Down
66 changes: 59 additions & 7 deletions src/monorepo/run/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ impl ReleaseInputs {
None => crate::git::build_head_ancestors(&repo).ok(),
};

let target_branch = if prerelease_ctx.is_prerelease() {
current_branch
} else {
config.workspace.branch.clone()
};

let changed_files = get_changed_files(&repo)?;
if !flags.quiet() {
log_changed_files(&changed_files);
Expand All @@ -106,7 +100,7 @@ impl ReleaseInputs {
all_tags,
tag_index,
fallback_ancestors,
target_branch,
target_branch: current_branch,
changed_files,
})
}
Expand Down Expand Up @@ -223,3 +217,61 @@ fn log_changed_files(changed_files: &[String]) {
}
tracing::debug!("");
}

#[cfg(test)]
mod tests {
use super::*;

fn git(dir: &Path, args: &[&str]) {
let status = std::process::Command::new("git")
.current_dir(dir)
.args(args)
.env_remove("GIT_DIR")
.env_remove("GIT_WORK_TREE")
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status()
.expect("git should be on PATH");
assert!(status.success(), "git {args:?} failed");
}

fn target_branch_on(checked_out: &str, workspace_branch: &str) -> String {
let dir = tempfile::tempdir().unwrap();
git(dir.path(), &["init", "-q", "-b", "main"]);
git(dir.path(), &["config", "user.email", "t@example.com"]);
git(dir.path(), &["config", "user.name", "t"]);
git(dir.path(), &["commit", "-q", "--allow-empty", "-m", "root"]);
git(dir.path(), &["checkout", "-q", "-B", checked_out]);

let mut config = Config::default();
config.workspace.branch = workspace_branch.to_string();

let flags = RunFlags {
dry_run: true,
verbose: false,
json: true,
release_json: false,
force: false,
draft: false,
shadow: false,
version_commands: false,
};
let access = RepoAccess {
channel: None,
force_unlock: false,
};
ReleaseInputs::resolve(dir.path(), &config, flags, access, &mut Timing::new(false))
.unwrap()
.target_branch
}

#[test]
fn stable_release_targets_the_checked_out_maintenance_branch() {
assert_eq!(target_branch_on("1.1.x", "main"), "1.1.x");
}

#[test]
fn stable_release_targets_workspace_branch_when_on_it() {
assert_eq!(target_branch_on("main", "main"), "main");
}
}
Loading