Skip to content

Commit

Permalink
add logging for 'switch -c' (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 12, 2023
1 parent 49a86e6 commit cefa509
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,19 @@ var switchCmd = &cobra.Command{
}

if createOption != "" {
prevBranch := client.Head.Reference
if err := client.Refs.AddBranch(client.RootGoitPath, createOption, client.Head.Commit.Hash); err != nil {
return fmt.Errorf("fail to create new branch %s: %w", createOption, err)
}
if err := client.Head.Update(client.Refs, client.RootGoitPath, createOption); 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 err := gLogger.WriteBranch(log.NewRecord(log.BranchRecord, nil, client.Head.Commit.Hash, client.Conf.GetUserName(), client.Conf.GetEmail(), time.Now(), fmt.Sprintf("Created from %s", prevBranch)), createOption); err != nil {
return fmt.Errorf("log error: %w", err)
}
}

return nil
Expand Down

0 comments on commit cefa509

Please sign in to comment.