SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::core::BranchManager Class Reference

Core service for managing version control branches (creation, deletion, switching). More...

#include <BranchManager.hxx>

Classes

struct  Branch
 Structure to hold the metadata for a single branch. More...

Public Member Functions

 BranchManager (std::shared_ptr< ISubject > event_bus)
 Constructs a BranchManager.
void createDefaultBranches ()
 Creates the initial set of default branches (e.g., 'main').
bool createBranch (const std::string &name)
 Creates a new branch pointing to a specific commit (usually HEAD).
bool createBranchFromCommit (const std::string &name, const std::string &commit_hash)
 Creates a new branch from a specific commit.
std::string getHeadCommit ()
 Get the current HEAD commit hash.
bool deleteBranch (const std::string &name, bool force=false)
 Deletes an existing branch.
bool renameBranch (const std::string &old_name, const std::string &new_name)
 Renames an existing branch.
bool switchBranch (const std::string &name)
 Switches the active branch to the specified name.
std::vector< BranchgetAllBranches () const
 Retrieves a list of all known branches, including their state.
std::string getCurrentBranch () const
 Retrieves the name of the currently active branch.
bool updateBranchHead (const std::string &branch_name, const std::string &commit_hash)
 Updates the commit hash that a specific branch points to.
bool branchExists (const std::string &name) const
 Checks if a branch with the given name exists.
std::string getBranchHead (const std::string &branch_name) const
 Retrieves the commit hash that a specific branch points to.

Static Public Member Functions

static bool isValidBranchName (const std::string &name)
 Checks if the given string is a valid name for a new branch.
static bool commitExists (const std::string &commit_hash)
 Checks if a commit exists (implementation assumed to check the object store).

Detailed Description

Core service for managing version control branches (creation, deletion, switching).

This class abstracts the details of branch storage and provides a high-level interface for branch manipulation. It uses an internal map to track branches and communicates status/errors via the ISubject event bus.

Constructor & Destructor Documentation

◆ BranchManager()

svcs::core::BranchManager::BranchManager ( std::shared_ptr< ISubject > event_bus)
explicit

Constructs a BranchManager.

Parameters
event_busA shared pointer to the event bus (ISubject) for communication.

Member Function Documentation

◆ branchExists()

bool svcs::core::BranchManager::branchExists ( const std::string & name) const

Checks if a branch with the given name exists.

Parameters
nameThe name of the branch to check.
Returns
true if the branch exists, false otherwise.

◆ commitExists()

bool svcs::core::BranchManager::commitExists ( const std::string & commit_hash)
static

Checks if a commit exists (implementation assumed to check the object store).

Parameters
commit_hashHash to check.
Returns
true if commit exists, false otherwise.

◆ createBranch()

bool svcs::core::BranchManager::createBranch ( const std::string & name)

Creates a new branch pointing to a specific commit (usually HEAD).

Parameters
nameThe name of the new branch.
Returns
true if the branch was created successfully, false otherwise.

◆ createBranchFromCommit()

bool svcs::core::BranchManager::createBranchFromCommit ( const std::string & name,
const std::string & commit_hash )

Creates a new branch from a specific commit.

Parameters
nameBranch name.
commit_hashHash of the commit to branch from.
Returns
true if successful, false otherwise.

◆ deleteBranch()

bool svcs::core::BranchManager::deleteBranch ( const std::string & name,
bool force = false )

Deletes an existing branch.

Prevents deletion of the current branch unless force is true.

Parameters
nameThe name of the branch to delete.
forceIf true, forces deletion even if the branch is not fully merged (implementation dependent).
Returns
true if the branch was deleted successfully, false otherwise.

◆ getAllBranches()

std::vector< BranchManager::Branch > svcs::core::BranchManager::getAllBranches ( ) const

Retrieves a list of all known branches, including their state.

Returns
A vector of Branch structures.

◆ getBranchHead()

std::string svcs::core::BranchManager::getBranchHead ( const std::string & branch_name) const

Retrieves the commit hash that a specific branch points to.

Parameters
branch_nameThe name of the branch.
Returns
The HEAD commit hash of the branch, or an empty string if the branch doesn't exist.

◆ getCurrentBranch()

std::string svcs::core::BranchManager::getCurrentBranch ( ) const

Retrieves the name of the currently active branch.

Returns
The string name of the current branch.

◆ getHeadCommit()

std::string svcs::core::BranchManager::getHeadCommit ( )

Get the current HEAD commit hash.

Returns
std::string The commit hash of current HEAD, or empty string if not found.

◆ isValidBranchName()

bool svcs::core::BranchManager::isValidBranchName ( const std::string & name)
static

Checks if the given string is a valid name for a new branch.

Parameters
nameThe string to validate.
Returns
true if the name is valid, false otherwise.

◆ renameBranch()

bool svcs::core::BranchManager::renameBranch ( const std::string & old_name,
const std::string & new_name )

Renames an existing branch.

Parameters
old_nameThe current name of the branch.
new_nameThe desired new name for the branch.
Returns
true if the branch was renamed successfully, false otherwise.

◆ switchBranch()

bool svcs::core::BranchManager::switchBranch ( const std::string & name)

Switches the active branch to the specified name.

This typically involves updating the HEAD reference and checking out files (the file checkout logic may reside in the RepositoryManager).

Parameters
nameThe name of the branch to switch to.
Returns
true if the switch was successful, false otherwise.

◆ updateBranchHead()

bool svcs::core::BranchManager::updateBranchHead ( const std::string & branch_name,
const std::string & commit_hash )

Updates the commit hash that a specific branch points to.

Parameters
branch_nameThe name of the branch to update.
commit_hashThe new commit hash.
Returns
true if the update was successful, false otherwise.

The documentation for this class was generated from the following files: