From 6a30308d826d7bd59c7b93b49a491f840f3cca6b Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Sun, 30 Apr 2023 21:58:47 +0530 Subject: [PATCH] add ldflags for branch to gothub update --- cmd/gothub/update.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/gothub/update.go b/cmd/gothub/update.go index 54d6848..82bb938 100644 --- a/cmd/gothub/update.go +++ b/cmd/gothub/update.go @@ -3,6 +3,7 @@ package gothub import ( "bytes" "fmt" + "strings" "github.com/spf13/cobra" @@ -30,6 +31,9 @@ func update() { os.Exit(1) } gitPull := exec.Command("git", "pull") + curBranch := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") + curBranchOut, _ := curBranch.CombinedOutput() + ldFlags := "-X codeberg.org/gothub/gothub/utils.Branch=" + strings.Replace(string(curBranchOut), "\n", "", -1) var out bytes.Buffer gitPull.Stdout = &out err := gitPull.Run() @@ -42,7 +46,7 @@ func update() { os.Exit(1) } if runtime.GOOS == "windows" { - err := exec.Command("go", "build", "-o", "gothub.exe").Run() + err := exec.Command("go", "build", "-o", "gothub.exe", ldFlags).Run() if err != nil { fmt.Println("Couldn't build GotHub.", err) os.Exit(1) @@ -51,7 +55,7 @@ func update() { os.Exit(0) } } else { - err := exec.Command("go", "build").Run() + err := exec.Command("go", "build", "-ldflags", ldFlags).Run() if err != nil { fmt.Println("Couldn't build GotHub.", err) os.Exit(1)