KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KIGIT::PROJECT_GIT_UTILS Class Reference

Utility class with helper functions for project level git operations. More...

#include <project_git_utils.h>

Static Public Member Functions

static git_repository * GetRepositoryForFile (const char *aFilename)
 Discover and open the repository that contains the given file.
 
static int CreateBranch (git_repository *aRepo, const wxString &aBranchName)
 Create a new branch based on HEAD.
 
static wxString GetCurrentHash (const wxString &aProjectFile, bool aShort)
 Return the current HEAD commit hash for the repository containing aProjectFile.
 
static bool RemoveVCS (git_repository *&aRepo, const wxString &aProjectPath=wxEmptyString, bool aRemoveGitDir=false, wxString *aErrors=nullptr)
 Remove version control from a directory by freeing the repository and optionally removing the .git directory.
 
static wxString ComputeSymlinkPreservingWorkDir (const wxString &aUserProjectPath, const wxString &aCanonicalWorkDir)
 Compute a working directory path that preserves symlinks from the user's project path.
 

Detailed Description

Utility class with helper functions for project level git operations.

Definition at line 35 of file project_git_utils.h.

Member Function Documentation

◆ ComputeSymlinkPreservingWorkDir()

wxString KIGIT::PROJECT_GIT_UTILS::ComputeSymlinkPreservingWorkDir ( const wxString & aUserProjectPath,
const wxString & aCanonicalWorkDir )
static

Compute a working directory path that preserves symlinks from the user's project path.

When a project is opened via a symlinked path, git_repository_workdir() returns the canonical (symlink-resolved) path. This causes path mismatches between the tree cache (which uses the user-provided symlinked path) and the git status results (which use canonical paths). This function computes a working directory path that preserves the symlinks from the user's original project path.

Parameters
aUserProjectPathThe path the user used to open the project (may contain symlinks)
aCanonicalWorkDirThe canonical workdir from git_repository_workdir()
Returns
Working directory path with symlinks preserved, or aCanonicalWorkDir on failure

Definition at line 86 of file project_git_utils.cpp.

References result.

Referenced by PROJECT_TREE_PANE::onGitRemoveVCS(), and PROJECT_TREE_PANE::ReCreateTreePrj().

◆ CreateBranch()

int KIGIT::PROJECT_GIT_UTILS::CreateBranch ( git_repository * aRepo,
const wxString & aBranchName )
static

Create a new branch based on HEAD.

Parameters
aRepoRepository in which to create the branch.
aBranchNameName of the new branch.
Returns
0 on success, libgit2 error code on failure.

Definition at line 44 of file project_git_utils.cpp.

References GIT_BACKEND::CreateBranch(), and GetGitBackend().

Referenced by PROJECT_TREE_PANE::onGitSwitchBranch().

◆ GetCurrentHash()

wxString KIGIT::PROJECT_GIT_UTILS::GetCurrentHash ( const wxString & aProjectFile,
bool aShort )
static

Return the current HEAD commit hash for the repository containing aProjectFile.

Parameters
aProjectFileAbsolute path to any file within the repository (typically the project file path).
aShortIf true, return the short (8 char) hash, otherwise full hash.
Returns
wxString containing the hash or "no hash" if unavailable.

Definition at line 55 of file project_git_utils.cpp.

References GetRepositoryForFile(), result, and TO_UTF8.

Referenced by PROJECT::TextVarResolver().

◆ GetRepositoryForFile()

git_repository * KIGIT::PROJECT_GIT_UTILS::GetRepositoryForFile ( const char * aFilename)
static

Discover and open the repository that contains the given file.

Parameters
aFilenameAbsolute path to a file inside the repository.
Returns
Newly opened git_repository or nullptr on failure.

Definition at line 39 of file project_git_utils.cpp.

References GetGitBackend(), and GIT_BACKEND::GetRepositoryForFile().

Referenced by GetCurrentHash(), PROJECT_TREE_PANE::onGitRemoveVCS(), and PROJECT_TREE_PANE::ReCreateTreePrj().

◆ RemoveVCS()

bool KIGIT::PROJECT_GIT_UTILS::RemoveVCS ( git_repository *& aRepo,
const wxString & aProjectPath = wxEmptyString,
bool aRemoveGitDir = false,
wxString * aErrors = nullptr )
static

Remove version control from a directory by freeing the repository and optionally removing the .git directory.

Parameters
aRepoRepository to free (will be set to nullptr)
aProjectPathPath to the project directory
aRemoveGitDirIf true, also remove the .git directory from disk
aErrorsOutput parameter for any error messages
Returns
True on success, false on failure

Definition at line 49 of file project_git_utils.cpp.

References GetGitBackend(), and GIT_BACKEND::RemoveVCS().

Referenced by PROJECT_TREE_PANE::EmptyTreePrj(), and PROJECT_TREE_PANE::ReCreateTreePrj().


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