Skip to content

Commit

Permalink
add logging for switch (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 12, 2023
1 parent ae17e68 commit 49a86e6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package cmd
import (
"errors"
"fmt"
"time"

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

Expand Down Expand Up @@ -38,9 +40,13 @@ var switchCmd = &cobra.Command{

// switch branch == update HEAD
if len(args) == 1 {
prevBranch := client.Head.Reference
if err := client.Head.Update(client.Refs, client.RootGoitPath, args[0]); err != nil {
return fmt.Errorf("fail to update HEAD: %w", err)
}
if err := gLogger.WriteHEAD(log.NewRecord(log.CheckoutRecord, client.Head.Commit.Hash, client.Head.Commit.Hash, client.Conf.GetUserName(), client.Conf.GetEmail(), time.Now(), fmt.Sprintf("moving from %s to %s", prevBranch, client.Head.Reference))); err != nil {
return fmt.Errorf("log error: %w", err)
}
}

if createOption != "" {
Expand Down

0 comments on commit 49a86e6

Please sign in to comment.