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.
 
static bool IsWithinProjectPath (const wxString &aAbsPath, const wxString &aProjectPath)
 Test whether an absolute file path lives inside the current project directory.
 

Detailed Description

Utility class with helper functions for project level git operations.

Definition at line 31 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 100 of file project_git_utils.cpp.

Referenced by PROJECT_TREE_PANE::onGitInitializeProject(), 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 46 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 69 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 35 of file project_git_utils.cpp.

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

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

◆ IsWithinProjectPath()

bool KIGIT::PROJECT_GIT_UTILS::IsWithinProjectPath ( const wxString & aAbsPath,
const wxString & aProjectPath )
static

Test whether an absolute file path lives inside the current project directory.

The git repository may span more than the KiCad project (the project is often a subdirectory of a larger repo). Commit and amend checklists must only offer files under the project directory, otherwise unrelated repository files leak into the commit (issue #15910). The project path is normalized to end in a separator before the prefix comparison so that a sibling such as "proj-extra/" is not treated as being inside "proj/". An empty project path matches nothing.

Parameters
aAbsPathAbsolute path of the file being tested.
aProjectPathAbsolute path of the project directory.
Returns
True if aAbsPath is within the project directory.

Definition at line 161 of file project_git_utils.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), PROJECT_TREE_PANE::onGitAmendCommit(), and PROJECT_TREE_PANE::onGitCommit().

◆ 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 57 of file project_git_utils.cpp.

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

Referenced by PROJECT_TREE_PANE::EmptyTreePrj().


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