Step 5: Checkpoint and Status.

Checkpoint re-hashes all tracked files, stores changed blobs, and
updates per-file timestamps only when content changes. Missing files
are skipped gracefully. Status compares each tracked entry against
the filesystem and reports ok/modified/missing.

CLI: sgard checkpoint [-m message], sgard status.
4 new tests (changed file, unchanged file, missing file, status).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 21:36:55 -07:00
parent 1550bdf940
commit 661c050d83
6 changed files with 371 additions and 6 deletions

33
cmd/sgard/checkpoint.go Normal file
View File

@@ -0,0 +1,33 @@
package main
import (
"fmt"
"github.com/kisom/sgard/garden"
"github.com/spf13/cobra"
)
var checkpointMessage string
var checkpointCmd = &cobra.Command{
Use: "checkpoint",
Short: "Re-hash all tracked files and update the manifest",
RunE: func(cmd *cobra.Command, args []string) error {
g, err := garden.Open(repoFlag)
if err != nil {
return err
}
if err := g.Checkpoint(checkpointMessage); err != nil {
return err
}
fmt.Println("Checkpoint complete.")
return nil
},
}
func init() {
checkpointCmd.Flags().StringVarP(&checkpointMessage, "message", "m", "", "checkpoint message")
rootCmd.AddCommand(checkpointCmd)
}

34
cmd/sgard/status.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import (
"fmt"
"github.com/kisom/sgard/garden"
"github.com/spf13/cobra"
)
var statusCmd = &cobra.Command{
Use: "status",
Short: "Show status of tracked files: ok, modified, or missing",
RunE: func(cmd *cobra.Command, args []string) error {
g, err := garden.Open(repoFlag)
if err != nil {
return err
}
statuses, err := g.Status()
if err != nil {
return err
}
for _, s := range statuses {
fmt.Printf("%-10s %s\n", s.State, s.Path)
}
return nil
},
}
func init() {
rootCmd.AddCommand(statusCmd)
}