71 wxString
result = wxT(
"no hash" );
76 git_reference* head =
nullptr;
78 if( git_repository_head( &head, repo ) == 0 )
80 const git_oid* oid = git_reference_target( head );
84 char buf[GIT_OID_HEXSZ + 1];
85 size_t len = aShort ? 9 : GIT_OID_HEXSZ + 1;
86 git_oid_tostr( buf, len, oid );
87 result = wxString::FromUTF8( buf );
90 git_reference_free( head );
93 git_repository_free( repo );
101 const wxString& aCanonicalWorkDir )
104 return aCanonicalWorkDir;
106 if( aUserProjectPath.IsEmpty() || aCanonicalWorkDir.IsEmpty() )
107 return aCanonicalWorkDir;
109 char resolvedPath[PATH_MAX];
111 if( realpath( aUserProjectPath.mb_str(), resolvedPath ) ==
nullptr )
112 return aCanonicalWorkDir;
114 wxString canonicalUserPath = wxString::FromUTF8( resolvedPath );
116 if( !canonicalUserPath.EndsWith( wxFileName::GetPathSeparator() ) )
117 canonicalUserPath += wxFileName::GetPathSeparator();
119 wxString canonicalWorkDirNorm = aCanonicalWorkDir;
121 if( !canonicalWorkDirNorm.EndsWith( wxFileName::GetPathSeparator() ) )
122 canonicalWorkDirNorm += wxFileName::GetPathSeparator();
128 if( canonicalUserPath == canonicalWorkDirNorm )
130 return aUserProjectPath.EndsWith( wxFileName::GetPathSeparator() )
132 : aUserProjectPath + wxFileName::GetPathSeparator();
139 userFn.AssignDir( aUserProjectPath );
141 wxFileName canonicalUserFn;
142 canonicalUserFn.AssignDir( canonicalUserPath );
144 wxFileName canonicalWorkDirFn;
145 canonicalWorkDirFn.AssignDir( canonicalWorkDirNorm );
147 while( canonicalUserFn.GetFullPath() != canonicalWorkDirFn.GetFullPath() )
149 if( canonicalUserFn.GetDirCount() == 0 || userFn.GetDirCount() == 0 )
150 return aCanonicalWorkDir;
152 canonicalUserFn.RemoveLastDir();
153 userFn.RemoveLastDir();
156 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.