Skip to content

Commit

Permalink
fix: the version is wrong when give pr (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
  • Loading branch information
LinuxSuRen and LinuxSuRen committed Jun 19, 2023
1 parent 3406573 commit bc1049f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cmd/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bc1049f

Please sign in to comment.