From 21cb0bc677173bc1e774eed7b3230c1a2e397da2 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 9 Sep 2026 22:29:01 -0600 Subject: [PATCH] refactor(net/gitshallow): finalize release API --- net/gitshallow/cmd/git-shallow-sync/main.go | 2 +- net/gitshallow/forcepush_test.go | 8 ++++---- net/gitshallow/gitshallow.go | 10 +++++----- net/gitshallow/gitshallow_integration_test.go | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/net/gitshallow/cmd/git-shallow-sync/main.go b/net/gitshallow/cmd/git-shallow-sync/main.go index 938a2a8..3e0c6d2 100644 --- a/net/gitshallow/cmd/git-shallow-sync/main.go +++ b/net/gitshallow/cmd/git-shallow-sync/main.go @@ -101,7 +101,7 @@ func main() { fmt.Fprintf(os.Stderr, "Syncing %s -> %s... ", url, absPath) t := time.Now() repo := gitshallow.New(url, absPath, cfg.Depth, cfg.Branch) - updated, err := repo.Fetch(ctx) + updated, err := repo.Update(ctx) if err != nil { fmt.Fprintln(os.Stderr) fmt.Fprintf(os.Stderr, "error: sync: %v\n", err) diff --git a/net/gitshallow/forcepush_test.go b/net/gitshallow/forcepush_test.go index c86a469..cf2efec 100644 --- a/net/gitshallow/forcepush_test.go +++ b/net/gitshallow/forcepush_test.go @@ -57,10 +57,10 @@ func TestRepo_ForcePushRecovery(t *testing.T) { // gitshallow clones, reads v1. repo := gitshallow.New(upstream, clone, 1, "main") - if updated, err := repo.Fetch(t.Context()); err != nil { - t.Fatalf("first Fetch: %v", err) + if updated, err := repo.Update(t.Context()); err != nil { + t.Fatalf("first Update: %v", err) } else if !updated { - t.Fatal("first Fetch: expected updated=true") + t.Fatal("first Update: expected updated=true") } got, err := os.ReadFile(filepath.Join(clone, "data.txt")) if err != nil { @@ -85,7 +85,7 @@ func TestRepo_ForcePushRecovery(t *testing.T) { // Use a fresh instance: the same *Repo has a 1s debounce that would // skip the follow-up fetch in this test's wall-clock window. repo2 := gitshallow.New(upstream, clone, 1, "main") - updated, err := repo2.Fetch(t.Context()) + updated, err := repo2.Update(t.Context()) if err != nil { t.Fatalf("post-force-push Fetch: %v", err) } diff --git a/net/gitshallow/gitshallow.go b/net/gitshallow/gitshallow.go index 7c4de60..2ffbae3 100644 --- a/net/gitshallow/gitshallow.go +++ b/net/gitshallow/gitshallow.go @@ -222,11 +222,11 @@ func (r *Repo) gc(ctx context.Context) error { } // Fetch clones the repo if missing, pulls otherwise, and conditionally runs -// GC based on GCInterval. Returns whether HEAD changed. Implements Fetcher. +// GC based on GCInterval. Returns whether HEAD changed. Implements Upstream. // Safe to call concurrently — concurrent callers share a single in-flight // fetch (via singleflight) and all receive the same result. To force a // pull regardless of MaxAge, set MaxAge=-1 before calling. -func (r *Repo) Fetch(ctx context.Context) (updated bool, err error) { +func (r *Repo) Update(ctx context.Context) (updated bool, err error) { // MaxAge: file-mtime gate (FETCH_HEAD is rewritten on every successful // fetch, so its mtime is "last time we talked to the remote"). if maxAge := r.effectiveMaxAge(); maxAge > 0 { @@ -309,9 +309,9 @@ func (f *RepoFile) Path() string { } // Fetch syncs the repo and reports whether this file changed since last call. -// Safe to call concurrently. Implements Fetcher. -func (f *RepoFile) Fetch(ctx context.Context) (bool, error) { - if _, err := f.repo.Fetch(ctx); err != nil { +// Safe to call concurrently. Implements Upstream. +func (f *RepoFile) Update(ctx context.Context) (bool, error) { + if _, err := f.repo.Update(ctx); err != nil { return false, err } info, err := os.Stat(f.Path()) diff --git a/net/gitshallow/gitshallow_integration_test.go b/net/gitshallow/gitshallow_integration_test.go index 0364db2..7084337 100644 --- a/net/gitshallow/gitshallow_integration_test.go +++ b/net/gitshallow/gitshallow_integration_test.go @@ -36,7 +36,7 @@ func TestRepo_Clone(t *testing.T) { os.RemoveAll(dir) repo := gitshallow.New(testRepoURL, dir, 1, "") - updated, err := repo.Fetch(t.Context()) + updated, err := repo.Update(t.Context()) if err != nil { t.Fatalf("Fetch (clone): %v", err) } @@ -64,12 +64,12 @@ func TestRepo_Pull_SameInstance(t *testing.T) { repo := gitshallow.New(testRepoURL, dir, 1, "") // Ensure cloned. - if _, err := repo.Fetch(t.Context()); err != nil { + if _, err := repo.Update(t.Context()); err != nil { t.Fatalf("initial Fetch: %v", err) } // Second pull on the same instance — already at HEAD, should not advance. - updated, err := repo.Fetch(t.Context()) + updated, err := repo.Update(t.Context()) if err != nil { t.Fatalf("second Fetch: %v", err) } @@ -84,13 +84,13 @@ func TestRepo_Pull_FreshInstance(t *testing.T) { // Ensure cloned via a first instance. first := gitshallow.New(testRepoURL, dir, 1, "") - if _, err := first.Fetch(t.Context()); err != nil { + if _, err := first.Update(t.Context()); err != nil { t.Fatalf("initial Fetch: %v", err) } // Fresh instance with no in-memory state — git HEAD on disk drives the check. fresh := gitshallow.New(testRepoURL, dir, 1, "") - updated, err := fresh.Fetch(t.Context()) + updated, err := fresh.Update(t.Context()) if err != nil { t.Fatalf("fresh-instance Fetch: %v", err) }