fix(server): don't try to reset next when dev is not based on main

This commit is contained in:
Paul Campbell 2024-05-07 18:58:43 +01:00
parent b1638a65fc
commit 7e79f4877a

View file

@ -51,6 +51,17 @@ pub async fn validate_positions(
); );
return Err(Error::BranchHasNoCommits(repo_config.branches().main())); return Err(Error::BranchHasNoCommits(repo_config.branches().main()));
}; };
// Dev must be on main branch, or user must rebase it
let dev_has_main = commit_histories.dev.iter().any(|commit| commit == &main);
if !dev_has_main {
warn!(
"Dev branch '{}' is not based on main branch '{}' - user should rebase onto main branch '{}'",
repo_config.branches().dev(),
repo_config.branches().main(),
repo_config.branches().main(),
);
return Err(Error::DevBranchNotBasedOn(repo_config.branches().main()));
}
// verify that next is an ancestor of dev, and force update to it main if it isn't // verify that next is an ancestor of dev, and force update to it main if it isn't
let Some(next) = commit_histories.next.first().cloned() else { let Some(next) = commit_histories.next.first().cloned() else {
warn!( warn!(
@ -119,16 +130,7 @@ pub async fn validate_positions(
); );
return Err(Error::DevBranchNotBasedOn(repo_config.branches().next())); // dev is not based on next return Err(Error::DevBranchNotBasedOn(repo_config.branches().next())); // dev is not based on next
} }
let dev_has_main = commit_histories.dev.iter().any(|commit| commit == &main);
if !dev_has_main {
warn!(
"Dev branch '{}' is not based on main branch '{}' - user should rebase onto main branch '{}'",
repo_config.branches().dev(),
repo_config.branches().main(),
repo_config.branches().main(),
);
return Err(Error::DevBranchNotBasedOn(repo_config.branches().main()));
}
let Some(dev) = commit_histories.dev.first().cloned() else { let Some(dev) = commit_histories.dev.first().cloned() else {
warn!( warn!(
"No commits on dev branch '{}'", "No commits on dev branch '{}'",