Keep candidate object inspection offline

This commit is contained in:
2026-10-07 20:18:13 +00:00
parent ff83af1e34
commit 02050016c1
4 changed files with 90 additions and 18 deletions

View File

@@ -2,6 +2,10 @@ package git
import (
"context"
"errors"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
@@ -28,6 +32,47 @@ func TestInspectTaggedSourceSupportsLightweightAndAnnotatedTags(t *testing.T) {
}
}
func TestCandidateObjectReadsStayLocalInPartialClones(t *testing.T) {
fixture := newRemoteFixture(t)
gitRun(t, fixture.work, "config", "uploadpack.allowFilter", "true")
blob := strings.TrimSpace(gitText(t, fixture.work, "rev-parse", "HEAD:source.txt"))
for _, filter := range []string{"blob:none", "tree:0"} {
t.Run(filter, func(t *testing.T) {
repository := filepath.Join(t.TempDir(), "partial")
gitRun(t, fixture.work, "clone", "--filter="+filter, "--no-checkout", "file://"+filepath.ToSlash(fixture.work), repository)
before := gitText(t, repository, "cat-file", "--batch-all-objects", "--batch-check=%(objectname)")
if strings.Contains(before, blob) {
t.Fatal("fixture contains the filtered blob")
}
gitRun(t, repository, "config", "remote.origin.url", "ssh://releasekit-test.invalid/source")
attempts := filepath.Join(t.TempDir(), "attempts")
transport := filepath.Join(t.TempDir(), "ssh")
if err := os.WriteFile(transport, []byte("#!/bin/sh\nprintf 'remote accessed\\n' >> \"$RELEASEKIT_GIT_ATTEMPTS\"\nexit 1\n"), 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("GIT_SSH_COMMAND", transport)
t.Setenv("RELEASEKIT_GIT_ATTEMPTS", attempts)
t.Setenv("GIT_NO_LAZY_FETCH", "0")
t.Setenv("GIT_ALLOW_PROTOCOL", "ssh")
if _, err := ReadTree(t.Context(), repository, fixture.commit); err == nil {
t.Fatal("tree inspection succeeded with unavailable objects")
}
_, err := ReadBlob(t.Context(), repository, blob)
var exitError *exec.ExitError
if !errors.As(err, &exitError) {
t.Fatalf("blob error %v lost its Git process cause", err)
}
if data, err := os.ReadFile(attempts); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("object inspection invoked remote transport: %q, %v", data, err)
}
after := gitText(t, repository, "cat-file", "--batch-all-objects", "--batch-check=%(objectname)")
if before != after {
t.Fatal("object inspection populated the object database")
}
})
}
}
func TestInspectTaggedSourceReportsDirtyCheckoutAndReadCommitFile(t *testing.T) {
fixture := newRemoteFixture(t)
gitRun(t, fixture.work, "tag", "v1.2.3")