From 7e79f4877a8a31e1a8610af5d9ca33a8bce7c651 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 7 May 2024 18:58:43 +0100 Subject: [PATCH] fix(server): don't try to reset next when dev is not based on main --- .../forgejo/branch/validate_positions.rs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/server/gitforge/forgejo/branch/validate_positions.rs b/src/server/gitforge/forgejo/branch/validate_positions.rs index 031063f..dc519d2 100644 --- a/src/server/gitforge/forgejo/branch/validate_positions.rs +++ b/src/server/gitforge/forgejo/branch/validate_positions.rs @@ -51,6 +51,17 @@ pub async fn validate_positions( ); 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 let Some(next) = commit_histories.next.first().cloned() else { warn!( @@ -119,16 +130,7 @@ pub async fn validate_positions( ); 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 { warn!( "No commits on dev branch '{}'",