29#include <unordered_map>
206 bool deleteBranch(
const std::string& name,
bool force =
false);
221 bool renameBranch(
const std::string& old_name,
const std::string& new_name);
277 bool updateBranchHead(
const std::string& branch_name,
const std::string& commit_hash);
303 std::string
getBranchHead(
const std::string& branch_name)
const;
331 static bool commitExists(
const std::string& commit_hash);
365 static void saveBranchToFile(
const std::string &branch_name,
const std::string &commit_hash);
376 static void deleteBranchFile(
const std::string &branch_name);
385 void loadCurrentBranch();
396 bool saveCurrentBranch()
const;
411 static std::string readFile(
const std::string& path);
424 static void writeFile(
const std::string& path,
const std::string& content);
437 static bool fileExists(
const std::string& path);
448 static void createDirectory(
const std::string& path);
461 static std::string getBranchesFilePath();
472 static std::string getHeadFilePath();
483 static std::string getBranchesDirectory();
492 std::unordered_map<std::string, Branch> branches;
501 std::string current_branch;
510 std::shared_ptr<ISubject> event_bus;
Defines the interface for the Subject (Publisher) component of the Observer pattern.
std::string getBranchHead(const std::string &branch_name) const
Retrieves the commit hash that a specific branch points to.
Definition BranchManager.cxx:274
bool renameBranch(const std::string &old_name, const std::string &new_name)
Renames an existing branch.
Definition BranchManager.cxx:138
BranchManager(std::shared_ptr< ISubject > event_bus)
Constructs a BranchManager.
Definition BranchManager.cxx:22
static bool isValidBranchName(const std::string &name)
Checks if the given string is a valid name for a new branch.
Definition BranchManager.cxx:291
std::vector< Branch > getAllBranches() const
Retrieves a list of all known branches, including their state.
Definition BranchManager.cxx:234
bool createBranchFromCommit(const std::string &name, const std::string &commit_hash)
Creates a new branch from a specific commit.
Definition BranchManager.cxx:57
bool branchExists(const std::string &name) const
Checks if a branch with the given name exists.
Definition BranchManager.cxx:270
std::string getCurrentBranch() const
Retrieves the name of the currently active branch.
Definition BranchManager.cxx:266
std::string getHeadCommit()
Get the current HEAD commit hash.
Definition BranchManager.cxx:250
void createDefaultBranches()
Creates the initial set of default branches (e.g., 'main').
Definition BranchManager.cxx:33
static bool commitExists(const std::string &commit_hash)
Checks if a commit exists (implementation assumed to check the object store).
Definition BranchManager.cxx:314
bool deleteBranch(const std::string &name, bool force=false)
Deletes an existing branch.
Definition BranchManager.cxx:105
bool switchBranch(const std::string &name)
Switches the active branch to the specified name.
Definition BranchManager.cxx:215
bool updateBranchHead(const std::string &branch_name, const std::string &commit_hash)
Updates the commit hash that a specific branch points to.
Definition BranchManager.cxx:192
bool createBranch(const std::string &name)
Creates a new branch pointing to a specific commit (usually HEAD).
Definition BranchManager.cxx:44
Core VCS data structures and object model.
Service layer components and infrastructure services.
Branch()
Default constructor.
Definition BranchManager.hxx:71
std::string head_commit
The hash of the latest commit on this branch.
Definition BranchManager.hxx:59
bool is_current
Flag indicating if this is the currently active branch.
Definition BranchManager.hxx:65
std::string name
The unique name of the branch.
Definition BranchManager.hxx:53