Skip to content

Commit

Permalink
logging for commit (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 11, 2023
1 parent e972ce9 commit 9202e4f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/JunNishimura/Goit/internal/log"
"github.com/JunNishimura/Goit/internal/object"
"github.com/JunNishimura/Goit/internal/store"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -69,11 +71,19 @@ func commit() error {
if err := client.Refs.UpdateBranchHash(client.RootGoitPath, client.Head.Reference, commit.Hash); err != nil {
return fmt.Errorf("fail to update branch %s: %w", client.Head.Reference, err)
}
// log
record := log.NewRecord(log.CommitRecord, client.Head.Commit.Hash, commit.Hash, client.Conf.GetUserName(), client.Conf.GetEmail(), time.Now(), message)
gLogger.WriteHEAD(record)

Check failure on line 76 in cmd/commit.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `gLogger.WriteHEAD` is not checked (errcheck)
gLogger.WriteBranch(record, client.Head.Reference)

Check failure on line 77 in cmd/commit.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `gLogger.WriteBranch` is not checked (errcheck)
} else {
// create
if err := client.Refs.AddBranch(client.RootGoitPath, client.Head.Reference, commit.Hash); err != nil {
return fmt.Errorf("fail to create branch %s: %w", client.Head.Reference, err)
}
// log
record := log.NewRecord(log.CommitRecord, nil, commit.Hash, client.Conf.GetUserName(), client.Conf.GetEmail(), time.Now(), message)
gLogger.WriteHEAD(record)

Check failure on line 85 in cmd/commit.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `gLogger.WriteHEAD` is not checked (errcheck)
gLogger.WriteBranch(record, client.Head.Reference)

Check failure on line 86 in cmd/commit.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `gLogger.WriteBranch` is not checked (errcheck)
}
if err := client.Head.Update(client.Refs, client.RootGoitPath, client.Head.Reference); err != nil {
return fmt.Errorf("fail to update HEAD: %w", err)
Expand Down

0 comments on commit 9202e4f

Please sign in to comment.