Skip to content

Commit ee72805

Browse files
Merge pull request #482 from supervacuus/fix/silence_git_stderr_coverall
fix: silence git stderr for coveralls writer
2 parents d8ca8d4 + 3549f2b commit ee72805

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/writers/coveralls-writer.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121

2222
#include "writer-base.hh"
2323

24-
static std::vector<std::string> run_command(const std::string& command)
24+
static std::vector<std::string> run_command(const std::string& command, bool stderr_enabled = true)
2525
{
2626
std::array<char, 128> buffer;
2727
std::vector<std::string> stdoutLines;
2828

29-
FILE* pipe = popen(command.c_str(), "r");
29+
std::string full_command = command;
30+
if (!stderr_enabled)
31+
full_command += " 2>/dev/null";
32+
33+
FILE* pipe = popen(full_command.c_str(), "r");
3034

3135
if (!pipe) {
3236
std::cerr << "[run_command] Failed calling popen()\n";
@@ -147,7 +151,7 @@ class CoverallsWriter : public WriterBase
147151

148152
void onStartup()
149153
{
150-
m_gitInfo = getGitInfoMap();
154+
m_gitInfo = getGitInfoMap();
151155
}
152156

153157
void onStop()
@@ -213,7 +217,7 @@ class CoverallsWriter : public WriterBase
213217
}
214218

215219
if (!m_gitInfo.empty() && !m_gitInfo["gitRootPath"].empty())
216-
strip_path = m_gitInfo["gitRootPath"] + "/";
220+
strip_path = m_gitInfo["gitRootPath"] + "/";
217221

218222
unsigned int filesLeft = m_files.size();
219223
for (FileMap_t::const_iterator it = m_files.begin();
@@ -283,13 +287,18 @@ class CoverallsWriter : public WriterBase
283287

284288
std::unordered_map<std::string, std::string> getGitInfoMap()
285289
{
286-
std::unordered_map<std::string, std::string> gitInfoMap;
290+
std::unordered_map<std::string, std::string> gitInfoMap;
291+
292+
// check whether we are inside a git work tree before collecting git metadata
293+
auto insideWorkTree = run_command("git rev-parse --is-inside-work-tree", false);
294+
if (insideWorkTree.size() != 1 || insideWorkTree[0] != "true")
295+
return gitInfoMap;
287296

288297
auto optionalGitInfo = run_command("git log -1 --pretty=format:'%H%n%aN%n%aE%n%cN%n%cE%n%s'");
289298
auto optionalGitBranch = run_command("git rev-parse --abbrev-ref HEAD");
290299
auto optionalGitRootPath = run_command("git rev-parse --show-toplevel");
291300
if (6 != optionalGitInfo.size())
292-
return gitInfoMap;
301+
return gitInfoMap;
293302

294303
gitInfoMap["commitHash"] = optionalGitInfo[0];
295304
gitInfoMap["authorName"] = optionalGitInfo[1];

0 commit comments

Comments
 (0)