Skip to content

Commit

Permalink
logging for reset soft (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 17, 2023
1 parent 124f594 commit 4762515
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"regexp"
"strconv"
"strings"
"time"

"github.com/JunNishimura/Goit/internal/log"
"github.com/JunNishimura/Goit/internal/store"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -65,9 +67,19 @@ var resetCmd = &cobra.Command{
}

// reset Head
prevHeadHash := client.Head.Commit.Hash
if err := client.Head.Reset(client.RootGoitPath, client.Refs, logRecord.Hash); err != nil {
return fmt.Errorf("fail to reset HEAD: %w", err)
}

// log
newRecord := log.NewRecord(log.ResetRecord, prevHeadHash, logRecord.Hash, client.Conf.GetUserName(), client.Conf.GetEmail(), time.Now(), fmt.Sprintf("moving to %s", args[0]))
if err := gLogger.WriteHEAD(newRecord); err != nil {
return fmt.Errorf("log error: %w", err)
}
if err := gLogger.WriteBranch(newRecord, client.Head.Reference); err != nil {
return fmt.Errorf("log error: %w", err)
}
}

return nil
Expand Down

0 comments on commit 4762515

Please sign in to comment.