Is there a way to obtain the name of the branch you are currently on from the PlatformIO environment kind of like you can get ${PROJECT_DIR} ?
PROJECT_DIR will give me the folder name of the local cloned GIT repo, but the project has many branches, and when I compile a certain branch I need to get the name of that branch passed to my C/C++ code.
Any help is appreciated. Thanks!
Thank you maxgerhardt, exactly what I needed!
build_flags =
; Latest commit hash; `%h` formats it to the short commit hash version:
; https://stackoverflow.com/a/5694454/666907
; https://git-scm.com/docs/pretty-formats/2.39.0
!echo '-D BUILD_GIT_COMMIT_HASH=\\"'$(git log -1 --format=%%h)'\\"'
This is for commit hash, you can get a branch name the same way.
Try
build_flags = !echo '-D BUILD_GIT_BRANCH=\\"'$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/")'\\"'
worked for me on OSX (unix)