Skip to content

Commit

Permalink
refactoring rev-parse command (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 18, 2023
1 parent 877b518 commit 8318d92
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cmd/revParse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (
"path/filepath"
"strings"

"github.com/JunNishimura/Goit/internal/store"
"github.com/spf13/cobra"
)

func revParse(refNames ...string) error {
func revParse(rootGoitPath string, head *store.Head, refNames ...string) error {
for _, refName := range refNames {
var refPath string
if strings.ToLower(refName) == "head" {
refPath = filepath.Join(client.RootGoitPath, "refs", "heads", client.Head.Reference)
refPath = filepath.Join(rootGoitPath, "refs", "heads", head.Reference)
} else {
refPath = filepath.Join(client.RootGoitPath, "refs", "heads", refName)
refPath = filepath.Join(rootGoitPath, "refs", "heads", refName)
}
hashBytes, err := os.ReadFile(refPath)
if err != nil {
Expand All @@ -42,7 +43,7 @@ var revParseCmd = &cobra.Command{
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if err := revParse(args...); err != nil {
if err := revParse(client.RootGoitPath, client.Head, args...); err != nil {
return err
}

Expand Down

0 comments on commit 8318d92

Please sign in to comment.