diff --git a/src/util/util.cc b/src/util/util.cc index 7a4c2165..bd163c80 100644 --- a/src/util/util.cc +++ b/src/util/util.cc @@ -56,6 +56,16 @@ std::string get_process_output(const std::string &command) return result; } +std::string get_env(const std::string &name) +{ + const char *value = std::getenv(name.c_str()); + + if (value == nullptr) + return {}; + + return std::string{value}; +} + bool is_git_repository() { #if defined(_WIN32) || defined(_WIN64) @@ -84,6 +94,11 @@ std::string get_git_commit() std::string get_git_toplevel_dir() { + const auto env_toplevel_dir = get_env("CLANGUML_GIT_TOPLEVEL_DIR"); + + if (!env_toplevel_dir.empty()) + return env_toplevel_dir; + return trim(get_process_output("git rev-parse --show-toplevel")); } diff --git a/src/util/util.h b/src/util/util.h index abf1a84e..b01e17f8 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -62,6 +62,8 @@ void setup_logging(bool verbose); std::string get_process_output(const std::string &command); +std::string get_env(const std::string &name); + bool is_git_repository(); std::string get_git_branch();