From b429a49504b1df6fa085cccbb3e461cd378b15c4 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
Date: Thu, 23 Apr 2020 23:44:03 +0200
Subject: [PATCH 1/3] mix.exs: Fix for MacOS

---
 mix.exs | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/mix.exs b/mix.exs
index b76aef180..021217400 100644
--- a/mix.exs
+++ b/mix.exs
@@ -220,32 +220,39 @@ defmodule Pleroma.Mixfile do
   defp version(version) do
     identifier_filter = ~r/[^0-9a-z\-]+/i
 
-    # Pre-release version, denoted from patch version with a hyphen
-    {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"])
+    {_gitpath, git_present} = System.cmd("sh", ["-c", "command -v git"])
 
     git_pre_release =
-      cond do
-        tag_err == 0 and describe_err == 0 ->
-          describe
-          |> String.trim()
-          |> String.replace(String.trim(tag), "")
-          |> String.trim_leading("-")
-          |> String.trim()
+      if git_present do
+        {tag, tag_err} =
+          System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true)
 
-        commit_hash_err == 0 ->
-          "0-g" <> String.trim(commit_hash)
+        {describe, describe_err} = System.cmd("git", ["describe", "--tags", "--abbrev=8"])
+        {commit_hash, commit_hash_err} = System.cmd("git", ["rev-parse", "--short", "HEAD"])
 
-        true ->
-          ""
+        # 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()
+
+          commit_hash_err == 0 ->
+            "0-g" <> String.trim(commit_hash)
+
+          true ->
+            ""
+        end
+      else
+        ""
       end
 
     # Branch name as pre-release version component, denoted with a dot
     branch_name =
-      with {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
+      with true <- git_present,
+           {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
            branch_name <- String.trim(branch_name),
            branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,
            true <-

From c63d6ba0b2686db847f70cf251f92bfed57c4e5f Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
Date: Thu, 23 Apr 2020 23:44:30 +0200
Subject: [PATCH 2/3] mix.exs: branch_name fallbacks to ""

---
 mix.exs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mix.exs b/mix.exs
index 021217400..15a65c0fb 100644
--- a/mix.exs
+++ b/mix.exs
@@ -266,7 +266,7 @@ defmodule Pleroma.Mixfile do
 
         branch_name
       else
-        _ -> "stable"
+        _ -> ""
       end
 
     build_name =

From 053c46153076f351c5273c2d6b1fb0843e7b6a6d Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
Date: Fri, 24 Apr 2020 00:26:24 +0200
Subject: [PATCH 3/3] mix.exs: proper check on 0, remove else in
 git_pre_release

---
 mix.exs | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/mix.exs b/mix.exs
index 15a65c0fb..ebb8bdb08 100644
--- a/mix.exs
+++ b/mix.exs
@@ -220,10 +220,10 @@ defmodule Pleroma.Mixfile do
   defp version(version) do
     identifier_filter = ~r/[^0-9a-z\-]+/i
 
-    {_gitpath, git_present} = System.cmd("sh", ["-c", "command -v git"])
+    {_cmdgit, cmdgit_err} = System.cmd("sh", ["-c", "command -v git"])
 
     git_pre_release =
-      if git_present do
+      if cmdgit_err == 0 do
         {tag, tag_err} =
           System.cmd("git", ["describe", "--tags", "--abbrev=0"], stderr_to_stdout: true)
 
@@ -243,15 +243,13 @@ defmodule Pleroma.Mixfile do
             "0-g" <> String.trim(commit_hash)
 
           true ->
-            ""
+            nil
         end
-      else
-        ""
       end
 
     # Branch name as pre-release version component, denoted with a dot
     branch_name =
-      with true <- git_present,
+      with 0 <- cmdgit_err,
            {branch_name, 0} <- System.cmd("git", ["rev-parse", "--abbrev-ref", "HEAD"]),
            branch_name <- String.trim(branch_name),
            branch_name <- System.get_env("PLEROMA_BUILD_BRANCH") || branch_name,