Question about getting git branch name.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about getting git branch name.

Steven Truppe
Hi everyone,

i want to have code lines like:

#define BUILD_VERSION

and the BUILD_VERSION should be the name of the actual branch the code
was compiled with, this way i can create a branch for each version and
name it like 0.1 so each version i'm using for release is an own branch.

I found many examples that shows me the branch name (like git status)
but i don't know a way to get only the name of the current branch so i
can for example execute_process to get the revision number into a
variable and then use add_definition(..) to add it as a compile definition.


best regards!

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Question about getting git branch name.

J Decker


On Sat, Jun 8, 2019 at 3:25 PM Steven Truppe <[hidden email]> wrote:
Hi everyone,

i want to have code lines like:

#define BUILD_VERSION

and the BUILD_VERSION should be the name of the actual branch the code
was compiled with, this way i can create a branch for each version and
name it like 0.1 so each version i'm using for release is an own branch.

I found many examples that shows me the branch name (like git status)
git branch
Hmm this shows a list of things, have to extract the one with a * on the beginning... cam probably use CMAKE list functions on the output.


EXECUTE_PROCESS(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND git rev-list --max-count=1 HEAD OUTPUT_VARIABLE CURRENT_REPO_REVISION )

gives me the last hash...

but i don't know a way to get only the name of the current branch so i
can for example execute_process to get the revision number into a
variable and then use add_definition(..) to add it as a compile definition.


best regards!

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Question about getting git branch name.

Juan E. Sanchez
In reply to this post by Steven Truppe
Hello,


suggests:

git rev-parse --abbrev-ref HEAD

Regards,

Juan


On Sat, Jun 8, 2019 at 5:25 PM Steven Truppe <[hidden email]> wrote:
Hi everyone,

i want to have code lines like:

#define BUILD_VERSION

and the BUILD_VERSION should be the name of the actual branch the code
was compiled with, this way i can create a branch for each version and
name it like 0.1 so each version i'm using for release is an own branch.

I found many examples that shows me the branch name (like git status)
but i don't know a way to get only the name of the current branch so i
can for example execute_process to get the revision number into a
variable and then use add_definition(..) to add it as a compile definition.


best regards!

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Question about getting git branch name.

Marc Herbert
In reply to this post by Steven Truppe
Try: git describe --all or git describe --all --dirty --long
git help describe

PS: a git branch is effectively a *moving* tag so for a BUILD_VERSION it seems wrong to rely on branches (--all) instead of tags. I think you mean BUILD_BRANCH instead of BUILD_VERSION.

Le sam. 8 juin 2019 à 15:25, Steven Truppe <[hidden email]> a écrit :
Hi everyone,

i want to have code lines like:

#define BUILD_VERSION

and the BUILD_VERSION should be the name of the actual branch the code
was compiled with, this way i can create a branch for each version and
name it like 0.1 so each version i'm using for release is an own branch.

I found many examples that shows me the branch name (like git status)
but i don't know a way to get only the name of the current branch so i
can for example execute_process to get the revision number into a
variable and then use add_definition(..) to add it as a compile definition.


best regards!

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake