Add read-only release readiness validation
This commit is contained in:
@@ -139,6 +139,30 @@ func (endpoint Endpoint) Recheck(ctx context.Context, repositoryDir string) erro
|
||||
return endpoint.verifyScopedURLs(ctx, repositoryDir)
|
||||
}
|
||||
|
||||
// QueryMain reads authoritative main without requiring a release tag or
|
||||
// comparing the branch to a candidate commit.
|
||||
func (endpoint Endpoint) QueryMain(ctx context.Context, repositoryDir string) (RemoteRef, error) {
|
||||
const mainRef = "refs/heads/main"
|
||||
output, err := run(ctx, repositoryDir, endpoint.scopedConfig(), "ls-remote", endpoint.ScopedName, mainRef)
|
||||
if err != nil {
|
||||
return RemoteRef{State: RefUnreadable}, fmt.Errorf("%w: query authoritative main at %s: %w", ErrRemoteStateUnreadable, DisplayURL(endpoint.PushURL), err)
|
||||
}
|
||||
main := RemoteRef{State: RefAbsent}
|
||||
for _, line := range strings.Split(strings.TrimSuffix(output, "\n"), "\n") {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
object, name, ok := strings.Cut(line, "\t")
|
||||
if !ok || !validObjectID(object) {
|
||||
return RemoteRef{State: RefUnreadable}, fmt.Errorf("%w: malformed ls-remote output %q", ErrRemoteStateUnreadable, displayDiagnostic(line))
|
||||
}
|
||||
if name == mainRef {
|
||||
main = mergeRef(main, object, false)
|
||||
}
|
||||
}
|
||||
return main, nil
|
||||
}
|
||||
|
||||
// Query reads exact main and tag refs. A command failure is unreadable,
|
||||
// never evidence that a ref is absent.
|
||||
func (endpoint Endpoint) Query(ctx context.Context, repositoryDir, tag string) (Snapshot, error) {
|
||||
|
||||
@@ -10,6 +10,23 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestQueryMainDoesNotRequireAReleaseTag(t *testing.T) {
|
||||
repo := newRemoteFixture(t)
|
||||
endpoint, err := Resolve(context.Background(), repo.work, "origin")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
main, err := endpoint.QueryMain(context.Background(), repo.work)
|
||||
if err != nil || main.State != RefPresent || main.Object != repo.commit {
|
||||
t.Fatalf("main = %#v, error = %v", main, err)
|
||||
}
|
||||
gitRun(t, repo.bare, "update-ref", "-d", "refs/heads/main")
|
||||
main, err = endpoint.QueryMain(context.Background(), repo.work)
|
||||
if err != nil || main.State != RefAbsent {
|
||||
t.Fatalf("missing main = %#v, error = %v", main, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveUsesPushURLAndQueriesWithoutMutation(t *testing.T) {
|
||||
repo := newRemoteFixture(t)
|
||||
configBefore := gitText(t, repo.work, "config", "--get-all", "remote.origin.url") + "\x00" + gitText(t, repo.work, "config", "--get-all", "remote.origin.pushurl")
|
||||
|
||||
@@ -47,6 +47,14 @@ func RepositoryRoot(ctx context.Context, directory string) (string, error) {
|
||||
return normalizeRepositoryRoot(root)
|
||||
}
|
||||
|
||||
// CheckTaggerIdentity checks Git's native committer identity without creating a tag.
|
||||
func CheckTaggerIdentity(ctx context.Context, directory string) error {
|
||||
if _, err := run(ctx, directory, nil, "var", "GIT_COMMITTER_IDENT"); err != nil {
|
||||
return fmt.Errorf("resolve Git tagger identity: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizeRepositoryRoot(root string) (string, error) {
|
||||
root = strings.TrimSuffix(root, "\n")
|
||||
resolved, err := filepath.EvalSymlinks(root)
|
||||
|
||||
Reference in New Issue
Block a user