38 git_repository* repo =
GetRepo();
43 git_status_options opts;
44 git_status_init_options( &opts, GIT_STATUS_OPTIONS_VERSION );
46 opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
47 opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX
48 | GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;
50 git_status_list* status_list =
nullptr;
52 if( git_status_list_new( &status_list, repo, &opts ) != GIT_OK )
59 bool hasChanges = ( git_status_list_entrycount( status_list ) > 0 );
66 std::map<wxString, FileStatus> fileStatusMap;
67 git_repository* repo =
GetRepo();
72 git_status_options status_options;
73 git_status_init_options( &status_options, GIT_STATUS_OPTIONS_VERSION );
74 status_options.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
75 status_options.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
78 std::string pathspec_str;
79 std::vector<const char*> pathspec_ptrs;
81 if( !aPathspec.IsEmpty() )
83 pathspec_str = aPathspec.ToStdString();
84 pathspec_ptrs.push_back( pathspec_str.c_str() );
86 status_options.pathspec.strings =
const_cast<char**
>( pathspec_ptrs.data() );
87 status_options.pathspec.count = pathspec_ptrs.size();
90 git_status_list* status_list =
nullptr;
92 if( git_status_list_new( &status_list, repo, &status_options ) != GIT_OK )
100 size_t count = git_status_list_entrycount( status_list );
101 wxString repoWorkDir( git_repository_workdir( repo ) );
103 for(
size_t ii = 0; ii < count; ++ii )
105 const git_status_entry* entry = git_status_byindex( status_list, ii );
106 std::string
path( entry->head_to_index ? entry->head_to_index->old_file.path
107 : entry->index_to_workdir->old_file.path );
109 wxString absPath = repoWorkDir +
path;
116 fileStatusMap[absPath] = fileStatus;
119 return fileStatusMap;
124 git_repository* repo =
GetRepo();
127 return wxEmptyString;
129 git_reference* currentBranchReference =
nullptr;
130 int rc = git_repository_head( ¤tBranchReference, repo );
133 if( currentBranchReference )
135 return git_reference_shorthand( currentBranchReference );
137 else if( rc == GIT_EUNBORNBRANCH )
140 return wxEmptyString;
145 return wxEmptyString;
150 const std::set<wxString>& aRemoteChanges,
151 std::map<wxString, FileStatus>& aFileStatus )
153 git_repository* repo =
GetRepo();
158 wxString repoWorkDir( git_repository_workdir( repo ) );
161 for(
auto& [absPath, fileStatus] : aFileStatus )
164 wxString relativePath = absPath;
165 if( relativePath.StartsWith( repoWorkDir ) )
167 relativePath = relativePath.Mid( repoWorkDir.length() );
169 relativePath.Replace( wxS(
"\\" ), wxS(
"/" ) );
173 std::string relativePathStd = relativePath.ToStdString();
178 if( aLocalChanges.count( relativePathStd ) )
182 else if( aRemoteChanges.count( relativePathStd ) )
192 git_repository* repo =
GetRepo();
195 return wxEmptyString;
197 const char* workdir = git_repository_workdir( repo );
200 return wxEmptyString;
202 return wxString( workdir );
207 if( aGitStatus & GIT_STATUS_IGNORED )
211 else if( aGitStatus & ( GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_MODIFIED ) )
215 else if( aGitStatus & ( GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_NEW ) )
219 else if( aGitStatus & ( GIT_STATUS_INDEX_DELETED | GIT_STATUS_WT_DELETED ) )
223 else if( aGitStatus & ( GIT_STATUS_CONFLICTED ) )
void ReportProgress(int aCurrent, int aTotal, const wxString &aMessage)
void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage) override
GIT_STATUS_HANDLER(KIGIT_COMMON *aCommon)
wxString GetCurrentBranchName()
Get the current branch name.
void UpdateRemoteStatus(const std::set< wxString > &aLocalChanges, const std::set< wxString > &aRemoteChanges, std::map< wxString, FileStatus > &aFileStatus)
Get status for modified files based on local/remote changes.
KIGIT_COMMON::GIT_STATUS ConvertStatus(unsigned int aGitStatus)
Convert git status flags to KIGIT_COMMON::GIT_STATUS.
wxString GetWorkingDirectory()
Get the repository working directory path.
bool HasChangedFiles()
Check if the repository has any changed files.
std::map< wxString, FileStatus > GetFileStatus(const wxString &aPathspec=wxEmptyString)
Get detailed file status for all files in the specified path.
virtual ~GIT_STATUS_HANDLER()
static wxString GetLastGitError()
git_repository * GetRepo() const
Get a pointer to the git repository.
const wxChar *const traceGit
Flag to enable Git debugging output.
std::unique_ptr< git_status_list, decltype([](git_status_list *aList) { git_status_list_free(aList) GitStatusListPtr
A unique pointer for git_status_list objects with automatic cleanup.
std::unique_ptr< git_reference, decltype([](git_reference *aRef) { git_reference_free(aRef) GitReferencePtr
A unique pointer for git_reference objects with automatic cleanup.
KIGIT_COMMON::GIT_STATUS status
wxLogTrace helper definitions.