Write a helper function to get the version of Git

This will be useful as we start to gate code on the version of Git that's installed.

A lot of code out in the wild seems to assume that the output of `git version`
is "git version $VERSION", so I'm assuming it's safe for git-crypt to rely
on that too.
This commit is contained in:
Andrew Ayer
2015-05-14 22:23:21 -07:00
parent 7880b30e8c
commit 439bcd852d

View File

@@ -60,6 +60,23 @@ static std::string attribute_name (const char* key_name)
}
}
static std::string git_version ()
{
std::vector<std::string> command;
command.push_back("git");
command.push_back("version");
std::stringstream output;
if (!successful_exit(exec_command(command, output))) {
throw Error("'git version' failed - is Git installed?");
}
std::string word;
output >> word; // "git"
output >> word; // "version"
output >> word; // "1.7.10.4"
return word;
}
static void git_config (const std::string& name, const std::string& value)
{
std::vector<std::string> command;