mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Interrogate the current state of a git repository.
Once the target directory is set, either on construction or using the dir() member function, the repo name, branch, commit hash, and modification status are interrogated with calls to git. This includes a list of uncommitted changes, including untracked files.
Examples:
Definition at line 52 of file gitRepo.hpp.
#include <sys/gitRepo.hpp>
Public Member Functions | |
gitRepo () | |
Default c'tor. More... | |
gitRepo (const std::string &d) | |
Constructor which sets the directory. More... | |
void | dir (const std::string &d) |
Set the directory. More... | |
std::string | dir () |
Get the current directory. More... | |
std::string | gitDir () |
Get the current repo's .git directory. More... | |
std::string | name () |
Get the repo's name. More... | |
std::string | branch () |
Get the current branch. More... | |
std::string | hash () |
Get the current commit hash. More... | |
bool | modified () |
Get whether the repo is modified. More... | |
bool | isNotCommitted (const std::string &file) |
Check whether a file is listed as not committed. More... | |
Protected Member Functions | |
int | getGitName () |
Get the name of the git repo. More... | |
int | getGitHash () |
Get the name of the current commit hash. More... | |
int | getGitModified () |
Get the modification status of the repo. More... | |
int | getGitFileState () |
Get the list of modified files, and the branch name. More... | |
Protected Attributes | |
std::string | m_dir |
The directory of the git repository. More... | |
std::string | m_name |
The repo name. More... | |
std::string | m_branch |
The current branch. More... | |
std::string | m_hash |
The complete commit hash. More... | |
bool | m_modified {false} |
The modification status, true or false. More... | |
std::set< std::string > | m_modifiedFiles |
Files which git lists as modified. More... | |
std::set< std::string > | m_deletedFiles |
Files which git lists as deleted. More... | |
std::set< std::string > | m_renamedFiles |
Files which git lists as renamed-from. More... | |
std::set< std::string > | m_renamedFiles2 |
Files which git lists as renamed-to. More... | |
std::set< std::string > | m_untrackedFiles |
Files which git lists as untracked. More... | |
mx::sys::gitRepo::gitRepo | ( | ) |
Default c'tor.
Definition at line 39 of file gitRepo.cpp.
mx::sys::gitRepo::gitRepo | ( | const std::string & | d | ) |
Constructor which sets the directory.
This results in the git repo status being interrogated.
Definition at line 43 of file gitRepo.cpp.
References dir().
std::string mx::sys::gitRepo::branch | ( | ) |
Get the current branch.
Definition at line 294 of file gitRepo.cpp.
References m_branch.
std::string mx::sys::gitRepo::dir | ( | ) |
Get the current directory.
Definition at line 59 of file gitRepo.cpp.
References m_dir.
Referenced by gitRepo(), getGitFileState(), getGitHash(), and getGitModified().
void mx::sys::gitRepo::dir | ( | const std::string & | d | ) |
Set the directory.
This results in the git repo status being interrogated.
Definition at line 48 of file gitRepo.cpp.
References getGitFileState(), getGitHash(), getGitModified(), getGitName(), and m_dir.
|
protected |
Get the list of modified files, and the branch name.
Called whenever m_dir is set.
Definition at line 176 of file gitRepo.cpp.
References dir(), gitDir(), m_branch, m_deletedFiles, m_modifiedFiles, m_renamedFiles, m_renamedFiles2, m_untrackedFiles, mx::ioutils::removeWhiteSpace(), and mx::ipc::runCommand().
Referenced by dir().
|
protected |
Get the name of the current commit hash.
Called whenever m_dir is set.
Definition at line 109 of file gitRepo.cpp.
References dir(), gitDir(), m_hash, and mx::ipc::runCommand().
Referenced by dir().
|
protected |
Get the modification status of the repo.
Called whenever m_dir is set.
Definition at line 149 of file gitRepo.cpp.
References dir(), gitDir(), m_modified, and mx::ipc::runCommand().
Referenced by dir().
|
protected |
Get the name of the git repo.
Called whenever m_dir is set.
Definition at line 69 of file gitRepo.cpp.
References gitDir(), m_name, mx::ioutils::pathFilename(), and mx::ipc::runCommand().
Referenced by dir().
std::string mx::sys::gitRepo::gitDir | ( | ) |
Get the current repo's .git directory.
Definition at line 64 of file gitRepo.cpp.
References m_dir.
Referenced by getGitFileState(), getGitHash(), getGitModified(), and getGitName().
std::string mx::sys::gitRepo::hash | ( | ) |
Get the current commit hash.
Definition at line 299 of file gitRepo.cpp.
References m_hash.
bool mx::sys::gitRepo::isNotCommitted | ( | const std::string & | file | ) |
Check whether a file is listed as not committed.
Not committed means modified, deleted, renamed (from or to), or untracked.
Definition at line 309 of file gitRepo.cpp.
References m_deletedFiles, m_modifiedFiles, m_renamedFiles, m_renamedFiles2, and m_untrackedFiles.
bool mx::sys::gitRepo::modified | ( | ) |
Get whether the repo is modified.
Definition at line 304 of file gitRepo.cpp.
References m_modified.
std::string mx::sys::gitRepo::name | ( | ) |
Get the repo's name.
Definition at line 289 of file gitRepo.cpp.
References m_name.
|
protected |
The current branch.
Definition at line 61 of file gitRepo.hpp.
Referenced by branch(), and getGitFileState().
|
protected |
Files which git lists as deleted.
Definition at line 66 of file gitRepo.hpp.
Referenced by getGitFileState(), and isNotCommitted().
|
protected |
The directory of the git repository.
Definition at line 57 of file gitRepo.hpp.
|
protected |
The complete commit hash.
Definition at line 62 of file gitRepo.hpp.
Referenced by getGitHash(), and hash().
|
protected |
The modification status, true or false.
Definition at line 63 of file gitRepo.hpp.
Referenced by getGitModified(), and modified().
|
protected |
Files which git lists as modified.
Definition at line 65 of file gitRepo.hpp.
Referenced by getGitFileState(), and isNotCommitted().
|
protected |
|
protected |
Files which git lists as renamed-from.
Definition at line 67 of file gitRepo.hpp.
Referenced by getGitFileState(), and isNotCommitted().
|
protected |
Files which git lists as renamed-to.
Definition at line 68 of file gitRepo.hpp.
Referenced by getGitFileState(), and isNotCommitted().
|
protected |
Files which git lists as untracked.
Definition at line 69 of file gitRepo.hpp.
Referenced by getGitFileState(), and isNotCommitted().