Make sure new projects have a main branch (vibe-kanban) (#450)

* Commit changes from coding agent for task attempt 55feb9b4-1b54-4181-b23e-a495886c39eb

* Cleanup script changes for task attempt 55feb9b4-1b54-4181-b23e-a495886c39eb

* Commit changes from coding agent for task attempt 55feb9b4-1b54-4181-b23e-a495886c39eb
This commit is contained in:
Louis Knight-Webb
2025-08-11 23:04:56 +01:00
committed by GitHub
parent 6f39cca4e6
commit 59c977e235
2 changed files with 54 additions and 24 deletions

View File

@@ -93,6 +93,42 @@ impl GitService {
Repository::open(repo_path).map_err(GitServiceError::from)
}
/// Initialize a new git repository with a main branch and initial commit
pub fn initialize_repo_with_main_branch(
&self,
repo_path: &Path,
) -> Result<(), GitServiceError> {
// Create directory if it doesn't exist
if !repo_path.exists() {
std::fs::create_dir_all(repo_path)?;
}
// Initialize git repository with main branch
let repo = Repository::init_opts(
repo_path,
git2::RepositoryInitOptions::new()
.initial_head("main")
.mkdir(true),
)?;
// Create initial commit
self.create_initial_commit(&repo)?;
Ok(())
}
/// Ensure an existing repository has a main branch (for empty repos)
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)?;
}
Ok(())
}
pub fn create_initial_commit(&self, repo: &Repository) -> Result<(), GitServiceError> {
let signature = repo.signature().unwrap_or_else(|_| {
// Fallback if no Git config is set