Skip to content

Commit

Permalink
add reset hard (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunNishimura committed Jun 18, 2023
1 parent ca78f48 commit 8167bec
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"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 @@ -51,6 +52,20 @@ func resetIndex(rootGoitPath string, logRecord *store.LogRecord, index *store.In
return nil
}

func resetWorkingTree(rootGoitPath string, index *store.Index) error {
for _, entry := range index.Entries {
obj, err := object.GetObject(rootGoitPath, entry.Hash)
if err != nil {
fmt.Errorf("fail to get object: %w", err)

Check failure on line 59 in cmd/reset.go

View workflow job for this annotation

GitHub Actions / lint

unusedresult: result of fmt.Errorf call not used (govet)
}
if err := obj.ReflectToWorkingTree(rootGoitPath, string(entry.Path)); err != nil {
fmt.Errorf("fail to reflect %s to working directory: %w", string(entry.Path), err)

Check failure on line 62 in cmd/reset.go

View workflow job for this annotation

GitHub Actions / lint

unusedresult: result of fmt.Errorf call not used (govet)
}
}

return nil
}

// resetCmd represents the reset command
var resetCmd = &cobra.Command{
Use: "reset",
Expand Down Expand Up @@ -107,6 +122,13 @@ var resetCmd = &cobra.Command{
}
}

// reset working tree
if isHard {
if err := resetWorkingTree(client.RootGoitPath, client.Idx); err != nil {
return fmt.Errorf("fail to reset working tree: %w", err)
}
}

return nil
},
}
Expand Down

0 comments on commit 8167bec

Please sign in to comment.