From f7c8434f6df970204c0f8ae83cd18d92db24b401 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Mon, 10 Jun 2019 09:33:33 +0300
Subject: [PATCH] Capture git branch and output

---
 cmake/git_version.cmake                       | 8 ++++++++
 components/common/cpp/include/ftl/config.h.in | 1 +
 components/common/cpp/src/config.cpp.in       | 1 +
 components/common/cpp/src/configuration.cpp   | 2 +-
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/cmake/git_version.cmake b/cmake/git_version.cmake
index 471ae6adc..2b850ab4f 100644
--- a/cmake/git_version.cmake
+++ b/cmake/git_version.cmake
@@ -8,6 +8,14 @@ if (Git_FOUND)
         WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
         RESULT_VARIABLE GIT_RESULT
         OUTPUT_VARIABLE VERSION
+        ERROR_QUIET
+		OUTPUT_STRIP_TRAILING_WHITESPACE)
+		
+	execute_process(COMMAND
+        "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
+        WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
+        RESULT_VARIABLE GIT_RESULT
+        OUTPUT_VARIABLE BRANCH
         ERROR_QUIET
         OUTPUT_STRIP_TRAILING_WHITESPACE)
         
diff --git a/components/common/cpp/include/ftl/config.h.in b/components/common/cpp/include/ftl/config.h.in
index 779918c14..5dcc8e575 100644
--- a/components/common/cpp/include/ftl/config.h.in
+++ b/components/common/cpp/include/ftl/config.h.in
@@ -22,6 +22,7 @@
 #cmakedefine HAVE_NANOGUI
 #cmakedefine HAVE_LIBARCHIVE
 
+extern const char *FTL_BRANCH;
 extern const char *FTL_VERSION_LONG;
 extern const char *FTL_VERSION;
 extern const int FTL_VERSION_MAJOR;
diff --git a/components/common/cpp/src/config.cpp.in b/components/common/cpp/src/config.cpp.in
index 15d1bbc11..fb0aadd4c 100644
--- a/components/common/cpp/src/config.cpp.in
+++ b/components/common/cpp/src/config.cpp.in
@@ -1,5 +1,6 @@
 #include <ftl/config.h>
 
+const char *FTL_BRANCH = "@BRANCH@";
 const char *FTL_VERSION_LONG = "@VERSION@";
 const char *FTL_VERSION = "";
 const int FTL_VERSION_MAJOR = 0;
diff --git a/components/common/cpp/src/configuration.cpp b/components/common/cpp/src/configuration.cpp
index af8bbd655..dc6e59b97 100644
--- a/components/common/cpp/src/configuration.cpp
+++ b/components/common/cpp/src/configuration.cpp
@@ -49,7 +49,7 @@ static Configurable *rootCFG = nullptr;
 
 bool ftl::running = true;
 int ftl::exit_code = 0;
-std::string ftl::branch_name = "";
+std::string ftl::branch_name = FTL_BRANCH;
 
 bool ftl::is_directory(const std::string &path) {
 #ifdef WIN32
-- 
GitLab