- # Pre-release version, denoted from patch version with a hyphen
- {git_tag, git_pre_release} =
- with {tag, 0} <-
- System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true),
- tag = String.trim(tag),
- {describe, 0} <- System.cmd("git", ["describe", "--tags", "--abbrev=8"]),
- describe = String.trim(describe),
- ahead <- String.replace(describe, tag, ""),
- ahead <- String.trim_leading(ahead, "-") do
- {String.replace_prefix(tag, "v", ""), if(ahead != "", do: String.trim(ahead))}
- else
- _ ->
- {commit_hash, 0} = System.cmd("git", ["rev-parse", "--short", "HEAD"])
- {nil, "0-g" <> String.trim(commit_hash)}
- end
+ {_cmdgit, cmdgit_err} = System.cmd("sh", ["-c", "command -v git"])
+
+ git_pre_release =
+ if cmdgit_err == 0 do
+ {tag, tag_err} =
+ System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true)
+
+ {describe, describe_err} = System.cmd("git", ["describe", "--tags", "--abbrev=8"])
+ {commit_hash, commit_hash_err} = System.cmd("git", ["rev-parse", "--short", "HEAD"])
+
+ # Pre-release version, denoted from patch version with a hyphen
+ cond do
+ tag_err == 0 and describe_err == 0 ->
+ describe
+ |> String.trim()
+ |> String.replace(String.trim(tag), "")
+ |> String.trim_leading("-")
+ |> String.trim()