75 wxString
result = wxT(
"no hash" );
80 git_reference* head =
nullptr;
82 if( git_repository_head( &head, repo ) == 0 )
84 const git_oid* oid = git_reference_target( head );
88 char buf[GIT_OID_HEXSZ + 1];
89 size_t len = aShort ? 9 : GIT_OID_HEXSZ + 1;
90 git_oid_tostr( buf, len, oid );
91 result = wxString::FromUTF8( buf );
94 git_reference_free( head );
97 git_repository_free( repo );
105 const wxString& aCanonicalWorkDir )
108 return aCanonicalWorkDir;
110 if( aUserProjectPath.IsEmpty() || aCanonicalWorkDir.IsEmpty() )
111 return aCanonicalWorkDir;
113 char resolvedPath[PATH_MAX];
115 if( realpath( aUserProjectPath.mb_str(), resolvedPath ) ==
nullptr )
116 return aCanonicalWorkDir;
118 wxString canonicalUserPath = wxString::FromUTF8( resolvedPath );
120 if( !canonicalUserPath.EndsWith( wxFileName::GetPathSeparator() ) )
121 canonicalUserPath += wxFileName::GetPathSeparator();
123 wxString canonicalWorkDirNorm = aCanonicalWorkDir;
125 if( !canonicalWorkDirNorm.EndsWith( wxFileName::GetPathSeparator() ) )
126 canonicalWorkDirNorm += wxFileName::GetPathSeparator();
132 if( canonicalUserPath == canonicalWorkDirNorm )
134 return aUserProjectPath.EndsWith( wxFileName::GetPathSeparator() )
136 : aUserProjectPath + wxFileName::GetPathSeparator();
143 userFn.AssignDir( aUserProjectPath );
145 wxFileName canonicalUserFn;
146 canonicalUserFn.AssignDir( canonicalUserPath );
148 wxFileName canonicalWorkDirFn;
149 canonicalWorkDirFn.AssignDir( canonicalWorkDirNorm );
151 while( canonicalUserFn.GetFullPath() != canonicalWorkDirFn.GetFullPath() )
153 if( canonicalUserFn.GetDirCount() == 0 || userFn.GetDirCount() == 0 )
154 return aCanonicalWorkDir;
156 canonicalUserFn.RemoveLastDir();
157 userFn.RemoveLastDir();
160 return userFn.GetPathWithSep();
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 ....
wxString result
Test unit parsing edge cases and error handling.