fix(worktree): mirror fetch follows moved tags and rewritten branches
This commit is contained in:
3 files changed
+67
-1
No files matched your search
@@ -5,6 +5,14 @@ release's per-component sections are labelled beneath its heading.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### archied
|
||||
|
||||
- A task no longer fails to prepare its worktree with "some refs were not updated" after a tag or branch moves on the forge.
|
||||
|
||||
### archie-ui
|
||||
|
||||
- The task page no longer flashes its loading state on every live update while a task runs.
|
||||
|
||||
## [1.60.0] - 2026-11-02
|
||||
|
||||
### archied
|
||||
|
||||
@@ -6,6 +6,10 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v6"
|
||||
"github.com/go-git/go-git/v6/plumbing"
|
||||
"github.com/go-git/go-git/v6/plumbing/object"
|
||||
)
|
||||
|
||||
func TestPruneMirrorsRemovesOnlyIdleUnusedMirrorsInsideRoot(t *testing.T) {
|
||||
@@ -91,3 +95,55 @@ func mkdir(t *testing.T, dir string) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// A forge may move a tag (a re-cut release, a rolling channel tag); the shared
|
||||
// mirror must follow it rather than refuse every later fetch.
|
||||
func TestEnsureMirrorFollowsAMovedTag(t *testing.T) {
|
||||
// The developer's own git config (commit signing) must not reach the fixture.
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("GIT_CONFIG_GLOBAL", os.DevNull)
|
||||
base := t.TempDir()
|
||||
upstream, err := git.PlainInit(filepath.Join(base, "o", "r.git"), false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
commit := func(msg string) plumbing.Hash {
|
||||
t.Helper()
|
||||
wt, err := upstream.Worktree()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h, err := wt.Commit(msg, &git.CommitOptions{AllowEmptyCommits: true, Author: &object.Signature{Name: "t", Email: "t@example.test", When: time.Now()}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return h
|
||||
}
|
||||
tagAt := func(h plumbing.Hash) {
|
||||
t.Helper()
|
||||
_ = upstream.DeleteTag("next")
|
||||
if _, err := upstream.CreateTag("next", h, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
tagAt(commit("first"))
|
||||
m := &Manager{WorkDir: t.TempDir(), BaseURL: "file://" + base}
|
||||
if _, err := m.ensureMirror(context.Background(), "o", "r"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
moved := commit("second")
|
||||
tagAt(moved)
|
||||
dir, err := m.ensureMirror(context.Background(), "o", "r")
|
||||
if err != nil {
|
||||
t.Fatalf("fetch after the tag moved: %v", err)
|
||||
}
|
||||
mirrored, err := git.PlainOpen(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ref, err := mirrored.Tag("next")
|
||||
if err != nil || ref.Hash() != moved {
|
||||
t.Fatalf("mirror tag = %v (%v), want %s", ref, err, moved)
|
||||
}
|
||||
}
|
||||
@@ -208,7 +208,9 @@ func (m *Manager) ensureMirror(ctx context.Context, owner, repo string) (string,
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("open mirror %s/%s: %w", owner, repo, err)
|
||||
}
|
||||
if err := r.FetchContext(ctx, &git.FetchOptions{ClientOptions: m.auth(), Tags: plumbing.AllTags}); err != nil &&
|
||||
// Force: the mirror copies the forge, so a moved tag or rewritten branch
|
||||
// replaces the local ref instead of failing every later fetch.
|
||||
if err := r.FetchContext(ctx, &git.FetchOptions{ClientOptions: m.auth(), Tags: plumbing.AllTags, Force: true}); err != nil &&
|
||||
!errors.Is(err, git.NoErrAlreadyUpToDate) {
|
||||
return "", fmt.Errorf("fetch mirror %s/%s: %w", owner, repo, err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user