Fix git status icons not showing when project opened via symlink

When a project is opened through a symlinked path, libgit2's
git_repository_workdir() returns the canonical path with symlinks
resolved. This caused a path mismatch between the tree cache
(which uses the user-provided symlinked path) and git status
results (which used canonical paths), preventing status icons
from being displayed.

The fix introduces SetProjectDir()/GetProjectDir() methods to
KIGIT_COMMON to store and use the user-provided project path.
A helper function computeSymlinkPreservingWorkDir() computes
the git working directory path while preserving symlinks from
the original user path.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21092
This commit is contained in:
Seth Hillbrand
2026-01-11 20:04:12 -08:00
parent 1143df89b1
commit 23765b6ebe
7 changed files with 161 additions and 24 deletions
+19
View File
@@ -46,6 +46,7 @@ KIGIT_COMMON::KIGIT_COMMON( git_repository* aRepo ) :
KIGIT_COMMON::KIGIT_COMMON( const KIGIT_COMMON& aOther ) :
// Initialize base class and member variables
m_repo( aOther.m_repo ),
m_projectDir( aOther.m_projectDir ),
m_connType( aOther.m_connType ),
m_remote( aOther.m_remote ),
m_hostname( aOther.m_hostname ),
@@ -69,6 +70,24 @@ git_repository* KIGIT_COMMON::GetRepo() const
return m_repo;
}
wxString KIGIT_COMMON::GetProjectDir() const
{
if( !m_projectDir.IsEmpty() )
return m_projectDir;
if( m_repo )
{
const char* workdir = git_repository_workdir( m_repo );
if( workdir )
return wxString( workdir );
}
return wxEmptyString;
}
wxString KIGIT_COMMON::GetCurrentBranchName() const
{
wxCHECK( m_repo, wxEmptyString );