66 return m_dir +
"/.git";
72 std::vector<std::string> stdOut, stdErr;
74 if(
ipc::runCommand( retVal, stdOut, stdErr, {
"git",
"--git-dir=" +
gitDir(),
"rev-parse",
"--show-toplevel"}) < 0)
76 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"error running git command");
82 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"error returned by git");
84 for(
size_t n=0; n< stdErr.size(); ++n)
86 std::cerr <<
"err: " << stdErr[n] <<
"\n";
94 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"nothing returned by git");
100 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"too much returned by git");
112 std::vector<std::string> stdOut, stdErr;
114 if(
ipc::runCommand( retVal, stdOut, stdErr, {
"git",
"--git-dir=" +
gitDir(),
"--work-tree=" +
dir(),
"log",
"-1",
"--format=%H"}) < 0)
116 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"error running git command");
120 if(stdErr.size() > 0)
122 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"error returned by git");
124 for(
size_t n=0; n< stdErr.size(); ++n)
126 std::cerr <<
"err: " << stdErr[n] <<
"\n";
132 if(stdOut.size() < 1)
134 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"nothing returned by git");
138 if(stdOut.size() > 1)
140 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"too much returned by git");
152 std::vector<std::string> stdOut, stdErr;
154 if(
ipc::runCommand( retVal, stdOut, stdErr, {
"git",
"--git-dir=" +
gitDir(),
"--work-tree=" +
dir(),
"diff-index",
"HEAD",
"--"}) < 0)
156 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"error running git command");
160 if(stdErr.size() > 0)
162 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"error returned by git");
163 for(
size_t n=0; n< stdErr.size(); ++n)
165 std::cerr <<
"err: " << stdErr[n] <<
"\n";
179 std::vector<std::string> stdOut, stdErr;
183 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"error running git command");
187 if(stdErr.size() > 0)
189 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"error returned by git");
191 for(
size_t n=0; n< stdErr.size(); ++n)
193 std::cerr <<
"err: " << stdErr[n] <<
"\n";
199 if(stdOut.size() < 1)
201 mxError(
"mx::sys::gitRepo::getGitName", MXE_PROCERR,
"nothing returned by git");
211 for(
size_t n=0; n < stdOut.size(); ++n)
213 if(stdOut[n].find(
"On b") != std::string::npos)
215 m_branch = stdOut[n].substr(
sizeof(
"On branch"));
217 else if(stdOut[n].find(
"Changes not") != std::string::npos)
222 while(stdOut[n].size() > 0)
224 if(n >= stdOut.size())
break;
226 if(stdOut[n].find(
"mod") != std::string::npos )
230 else if(stdOut[n].find(
"del") != std::string::npos )
234 else if(stdOut[n].find(
"ren") != std::string::npos )
236 size_t a = stdOut[n].find(
" -> ");
244 else if(stdOut[n].find(
"Changes to") != std::string::npos)
249 while(stdOut[n].size() > 0)
251 if(n >= stdOut.size())
break;
253 if(stdOut[n].find(
"mod") != std::string::npos )
257 else if(stdOut[n].find(
"del") != std::string::npos )
261 else if(stdOut[n].find(
"ren") != std::string::npos )
263 size_t a = stdOut[n].find(
" -> ");
271 else if(stdOut[n].find(
"Untracked") != std::string::npos)
277 while(stdOut[n].size() > 0)
279 if(n >= stdOut.size())
break;
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.
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.
Declares and defines the mxlib error reporting system.
Process interface facilities.
Utilities for working with strings.