3

I wanted to get the current git branch name to build binaries with a filename that contains the branch name. Is that possible in Netbeans(7.1) with ant ?

Rostislav Matl
  • 3,781
  • 4
  • 23
  • 50
PeterMmm
  • 22,286
  • 12
  • 68
  • 104

3 Answers3

5

If you do not want to deal with env variables (as suggested in the solution above) AND if the git command is available from your command line, an alternate solution would be using ANT exec:

<exec executable="git" outputproperty="git.branch"
 failifexecutionfails="false">
 <arg line="rev-parse --abbrev-ref HEAD"/>
</exec>
<echo message="Current branch: ${git.branch}"/> 

(Solution basically combines http://llbit.se/?p=1876 and How to get the current branch name in Git?)

Community
  • 1
  • 1
hhappel
  • 51
  • 1
  • 1
2

One way you can get the current branch name and set it into the branch_name env variable is:

branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}

You can put this in a shell script to execute this and store it as an environment variable, and then use this env. variable inside ant.

Source - How to programmatically determine the current checked out Git branch

Community
  • 1
  • 1
skyronic
  • 1,507
  • 1
  • 11
  • 14
0

If netbeans/ant can execute shell commands then this is possible.

See How to programmatically determine the current checked out Git branch on how to get the name of the current branch - you then just need to integrate this in your build scripts so they can use the value.

Community
  • 1
  • 1
ThiefMaster
  • 285,213
  • 77
  • 557
  • 610