From d2a5f73256ac1b859742c09392869d3f64e5ee1d Mon Sep 17 00:00:00 2001 From: rho song Date: Thu, 18 Mar 2021 08:46:44 -0700 Subject: [PATCH] DRY the logic --- modules/git/git.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/modules/git/git.go b/modules/git/git.go index d5c444a7c..d13594756 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -26,17 +26,7 @@ func GetCurrentBranchNameE(t testing.TestingT) (string, error) { cmd := exec.Command("git", "branch", "--show-current") bytes, err := cmd.Output() if err != nil { - cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") - bytes, err := cmd.Output() - if err != nil { - return "", err - } - name := strings.TrimSpace(string(bytes)) - if name == "HEAD" { - return "", nil - } - - return name, nil + return GetCurrentBranchNameOldE(t) } name := strings.TrimSpace(string(bytes)) @@ -48,7 +38,8 @@ func GetCurrentBranchNameE(t testing.TestingT) (string, error) { } // GetCurrentBranchNameOldE retrieves the current branch name or -// empty string in case of detached state. +// empty string in case of detached state. This uses the older pattern +// of `git rev-parse` rather than `git branch --show-current`. func GetCurrentBranchNameOldE(t testing.TestingT) (string, error) { cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") bytes, err := cmd.Output()