From 56655dffcacecc76a210ee9d9ce2a3f7574faafe Mon Sep 17 00:00:00 2001 From: Alex Netsch Date: Tue, 23 Sep 2025 10:42:20 +0100 Subject: [PATCH] Fix ensure_main_branch_exists (#806) --- crates/services/src/services/git.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/services/src/services/git.rs b/crates/services/src/services/git.rs index 5582fb7e..8d32290f 100644 --- a/crates/services/src/services/git.rs +++ b/crates/services/src/services/git.rs @@ -177,11 +177,19 @@ impl GitService { pub fn ensure_main_branch_exists(&self, repo_path: &Path) -> Result<(), GitServiceError> { let repo = self.open_repo(repo_path)?; - // Only create initial commit if repository is empty - if repo.is_empty()? { - self.create_initial_commit(&repo)?; + match repo.branches(None) { + Ok(branches) => { + if branches.count() == 0 { + // No branches exist - create initial commit on main branch + self.create_initial_commit(&repo)?; + } + } + Err(e) => { + return Err(GitServiceError::InvalidRepository(format!( + "Failed to list branches: {e}" + ))); + } } - Ok(()) }