Skip to content

[gitalisk][repository] Implement proper listBranches functionality in Gitalisk

Problem to Solve

The CoreGitaliskRepository list_branches() method currently returns a hardcoded ["main"] vector instead of actually listing repository branches. We will need the ability to get a list of branches for a repository.

Proposal

  1. Replace hardcoded list_branches() implementation in CoreGitaliskRepository with actual git branch listing
  2. Use git branch command to retrieve local branches from repository
  3. Handle repositories with no branches (newly initialized repos)
  4. Add option to include remote branches if needed
  5. Ensure proper error handling for invalid repositories
  6. Update existing tests and add comprehensive branch listing test coverage

Further Details

Current Implementation:

rust

pub fn list_branches(&self) -> Result<Vec<String>, std::io::Error> { let branch_names: Vec<String> = vec!["main".to_string()]; Ok(branch_names) }

Acceptance Criteria:

  • Method returns actual local branches present in repository
  • Handles repositories with zero branches
  • Handles repositories with non-standard default branch names
  • Proper error handling for invalid or corrupted repositories
  • Test coverage for various branch scenarios (single branch, multiple branches, no branches)

Implementation Notes:

  • Use git branch --format='%(refname:short)' for clean branch name output
  • Consider whether remote branches should be included or handled separately
    • Could maybe use a option that can be passed to include remote branches

Links / References