Skip to content

Commit

Permalink
fix: the version is wrong when give pr
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Jun 19, 2023
1 parent 3406573 commit fd5341c
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

Check warning on line 84 in cmd/checkout.go

View check run for this annotation

Codecov / codecov/patch

cmd/checkout.go#L84

Added line #L84 was not covered by tests

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

Check warning on line 100 in cmd/checkout.go

View check run for this annotation

Codecov / codecov/patch

cmd/checkout.go#L100

Added line #L100 was not covered by tests

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)

Check warning on line 136 in cmd/checkout.go

View check run for this annotation

Codecov / codecov/patch

cmd/checkout.go#L136

Added line #L136 was not covered by tests
}

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)

Check warning on line 140 in cmd/checkout.go

View check run for this annotation

Codecov / codecov/patch

cmd/checkout.go#L139-L140

Added lines #L139 - L140 were not covered by tests
}
}
return
Expand Down

0 comments on commit fd5341c

Please sign in to comment.