From 439bcd852d85819c9a541cb38a29389221f8788b Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Thu, 14 May 2015 22:23:21 -0700 Subject: [PATCH] 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. --- commands.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/commands.cpp b/commands.cpp index b23f185..f984132 100644 --- a/commands.cpp +++ b/commands.cpp @@ -60,6 +60,23 @@ static std::string attribute_name (const char* key_name) } } +static std::string git_version () +{ + std::vector 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 command;