From bc1049f443acfa94f07ebca80c4b6b5185bea148 Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Mon, 19 Jun 2023 18:05:49 +0800 Subject: [PATCH] fix: the version is wrong when give pr (#37) Co-authored-by: rick --- cmd/checkout.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/checkout.go b/cmd/checkout.go index 9ecdcd7..c913345 100644 --- a/cmd/checkout.go +++ b/cmd/checkout.go @@ -81,6 +81,7 @@ func (o *checkoutOption) runE(c *cobra.Command, args []string) (err error) { var wd *git.Worktree var remotes []*git.Remote + var version string if remotes, err = repo.Remotes(); err != nil { return @@ -96,6 +97,7 @@ func (o *checkoutOption) runE(c *cobra.Command, args []string) (err error) { if wd, err = repo.Worktree(); err == nil { if c.Flags().Changed("branch") { c.Printf("Switched to branch '%s'\n", o.branch) + version = o.branch if err = wd.Checkout(&git.CheckoutOptions{ Branch: plumbing.NewBranchReferenceName(o.branch), @@ -131,13 +133,11 @@ func (o *checkoutOption) runE(c *cobra.Command, args []string) (err error) { err = fmt.Errorf("unable to checkout git branch: %s, error: %v", o.tag, err) return } + version = fmt.Sprintf("%d", o.pr) } - var head *plumbing.Reference - if head, err = repo.Head(); err == nil { - if o.versionOutput != "" { - err = os.WriteFile(o.versionOutput, []byte(strings.TrimPrefix(head.Name().Short(), o.trimVersionPrefix)), 0444) - } + if o.versionOutput != "" { + err = os.WriteFile(o.versionOutput, []byte(strings.TrimPrefix(version, o.trimVersionPrefix)), 0444) } } return