63 return m_dir +
"/.git";
69 std::vector<std::string> stdOut, stdErr;
71 if(
ipc::runCommand( retVal, stdOut, stdErr, {
"git",
"--git-dir=" +
gitDir(),
"rev-parse",
"--show-toplevel" } ) <
78 if( stdErr.size() > 0 )
82 for(
size_t n = 0; n < stdErr.size(); ++n )
84 std::cerr <<
"err: " << stdErr[n] <<
"\n";
90 if( stdOut.size() < 1 )
96 if( stdOut.size() > 1 )
110 std::vector<std::string> stdOut, stdErr;
115 {
"git",
"--git-dir=" +
gitDir(),
"--work-tree=" +
dir(),
"log",
"-1",
"--format=%H" } ) < 0 )
121 if( stdErr.size() > 0 )
125 for(
size_t n = 0; n < stdErr.size(); ++n )
127 std::cerr <<
"err: " << stdErr[n] <<
"\n";
133 if( stdOut.size() < 1 )
139 if( stdOut.size() > 1 )
153 std::vector<std::string> stdOut, stdErr;
158 {
"git",
"--git-dir=" +
gitDir(),
"--work-tree=" +
dir(),
"diff-index",
"HEAD",
"--" } ) < 0 )
164 if( stdErr.size() > 0 )
167 for(
size_t n = 0; n < stdErr.size(); ++n )
169 std::cerr <<
"err: " << stdErr[n] <<
"\n";
183 std::vector<std::string> stdOut, stdErr;
186 retVal, stdOut, stdErr, {
"git",
"--git-dir=" +
gitDir(),
"--work-tree=" +
dir(),
"status" } ) < 0 )
192 if( stdErr.size() > 0 )
196 for(
size_t n = 0; n < stdErr.size(); ++n )
198 std::cerr <<
"err: " << stdErr[n] <<
"\n";
204 if( stdOut.size() < 1 )
216 for(
size_t n = 0; n < stdOut.size(); ++n )
218 if( stdOut[n].find(
"On b" ) != std::string::npos )
220 m_branch = stdOut[n].substr(
sizeof(
"On branch" ) );
222 else if( stdOut[n].find(
"Changes not" ) != std::string::npos )
227 while( stdOut[n].size() > 0 )
229 if( n >= stdOut.size() )
232 if( stdOut[n].find(
"mod" ) != std::string::npos )
236 else if( stdOut[n].find(
"del" ) != std::string::npos )
240 else if( stdOut[n].find(
"ren" ) != std::string::npos )
242 size_t a = stdOut[n].find(
" -> " );
245 stdOut[n].substr(
sizeof(
"renamed:" ), a -
sizeof(
"renamed:" ) ) ) );
251 else if( stdOut[n].find(
"Changes to" ) != std::string::npos )
256 while( stdOut[n].size() > 0 )
258 if( n >= stdOut.size() )
261 if( stdOut[n].find(
"mod" ) != std::string::npos )
265 else if( stdOut[n].find(
"del" ) != std::string::npos )
269 else if( stdOut[n].find(
"ren" ) != std::string::npos )
271 size_t a = stdOut[n].find(
" -> " );
274 stdOut[n].substr(
sizeof(
"renamed: " ), a -
sizeof(
"renamed:" ) ) ) );
280 else if( stdOut[n].find(
"Untracked" ) != std::string::npos )
286 while( stdOut[n].size() > 0 )
288 if( n >= stdOut.size() )
int getGitName()
Get the name of the git repo.
std::string gitDir()
Get the current repo's .git directory.
std::set< std::string > m_renamedFiles
Files which git lists as renamed-from.
std::string m_branch
The current branch.
std::set< std::string > m_renamedFiles2
Files which git lists as renamed-to.
bool isNotCommitted(const std::string &file)
Check whether a file is listed as not committed.
std::string m_dir
The directory of the git repository.
int getGitHash()
Get the name of the current commit hash.
std::string branch()
Get the current branch.
std::string name()
Get the repo's name.
std::string m_name
The repo name.
std::set< std::string > m_untrackedFiles
Files which git lists as untracked.
std::set< std::string > m_deletedFiles
Files which git lists as deleted.
std::set< std::string > m_modifiedFiles
Files which git lists as modified.
std::string dir()
Get the current directory.
std::string m_hash
The complete commit hash.
bool modified()
Get whether the repo is modified.
int getGitModified()
Get the modification status of the repo.
bool m_modified
The modification status, true or false.
int getGitFileState()
Get the list of modified files, and the branch name.
std::string hash()
Get the current commit hash.
Declarations of utilities for working with files.
Interrogate the current state of a git repository (declarations)
int runCommand(int &retVal, std::vector< std::string > &commandOutput, std::vector< std::string > &commandStderr, const std::vector< std::string > &commandList)
Runs a command (with parameters) passed in using fork/exec.
@ procerr
An error occurred while starting a process.
error_t mxlib_error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.
std::string pathFilename(const std::string &fname)
Get the base filename.
void removeWhiteSpace(std::string &outstr, const std::string &instr)
Remove all white space from a string.
Process interface facilities.
Utilities for working with strings.