#development #elixir #git #tools
The following snippet allows you to extract the SHA1 of the git commit from within elixir. It is useful to attach the SHA1 to your release or code so that if therea are any issues you can quickly checkout the commit and look into it.
You can also get the branch name if required.
1def git_commit_sha() do
2 System.cmd("git", ["rev-parse", "--short", "HEAD"])
3 |> elem(0)
4 |> String.trim()
5end
6
7def git_branch_name() do
8 System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"])
9 |> elem(0)
10 |> String.trim()
11end
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.