Skip to content

Commit

Permalink
Write a helper function to get the version of Git
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AGWA committed May 15, 2015
1 parent 7880b30 commit 439bcd8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 439bcd8

Please sign in to comment.