From a86c6ee6fab3e570a605c767113e3f9c835dac39 Mon Sep 17 00:00:00 2001 From: rkfg Date: Thu, 19 Nov 2020 14:11:46 +0300 Subject: [PATCH] Less nested ifs in build.go --- cmd/build.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/cmd/build.go b/cmd/build.go index 507a1aa..e28276c 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -91,19 +91,12 @@ func versionFlags() string { date := time.Now().Format("01-02-2006 15:04:05 -0700 MST") result := fmt.Sprintf(`-X "main.date=%s"`, date) version := "" - tag, err := exec.Command("git", "tag", "--contains", "HEAD").Output() - if err != nil || string(tag) == "" { - branch, err := exec.Command("git", "branch", "--show-current").Output() - if err != nil || string(branch) == "" { - commit, err := exec.Command("git", "log", "--pretty=format:%h", "-n1").Output() - if err == nil && string(commit) != "" { - version = fmt.Sprintf("commit %s", commit) - } - } else { - version = fmt.Sprintf("branch %s", branch) - } - } else { + if tag, err := exec.Command("git", "tag", "--contains", "HEAD").Output(); err == nil && string(tag) != "" { version = string(tag) + } else if branch, err := exec.Command("git", "branch", "--show-current").Output(); err == nil && string(tag) != "" { + version = fmt.Sprintf("branch %s", branch) + } else if commit, err := exec.Command("git", "log", "--pretty=format:%h", "-n1").Output(); err == nil && string(commit) != "" { + version = fmt.Sprintf("commit %s", commit) } if version != "" { result = fmt.Sprintf(`%s -X "main.version=%s"`, result, strings.TrimSuffix(version, "\n"))