Resume and safely clean recorded rehearsals
This commit is contained in:
@@ -4,9 +4,34 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// QueryLocalDiagnosticTag distinguishes an absent local ref from an unreadable
|
||||
// or non-annotated ref; an error never establishes absence.
|
||||
func QueryLocalDiagnosticTag(ctx context.Context, repo, tag string) (RefState, AnnotatedTag, error) {
|
||||
if !strings.HasPrefix(tag, "releasekit-test/") {
|
||||
return RefUnreadable, AnnotatedTag{}, errors.New("diagnostic tag is required")
|
||||
}
|
||||
if err := CheckTagRef(ctx, repo, tag); err != nil {
|
||||
return RefUnreadable, AnnotatedTag{}, err
|
||||
}
|
||||
_, err := run(ctx, repo, nil, "show-ref", "--verify", "--quiet", "refs/tags/"+tag)
|
||||
if err != nil {
|
||||
var exit *exec.ExitError
|
||||
if errors.As(err, &exit) && exit.ExitCode() == 1 && ctx.Err() == nil {
|
||||
return RefAbsent, AnnotatedTag{}, nil
|
||||
}
|
||||
return RefUnreadable, AnnotatedTag{}, err
|
||||
}
|
||||
observed, err := ReadAnnotatedTag(ctx, repo, tag)
|
||||
if err != nil {
|
||||
return RefUnreadable, AnnotatedTag{}, err
|
||||
}
|
||||
return RefPresent, observed, nil
|
||||
}
|
||||
|
||||
func checkDiagnosticTag(ctx context.Context, repo, tag, object, commit string) error {
|
||||
if !strings.HasPrefix(tag, "releasekit-test/") || !ValidObjectID(object) || !ValidObjectID(commit) {
|
||||
return errors.New("a diagnostic tag and exact tag object and commit are required")
|
||||
|
||||
@@ -30,6 +30,18 @@ func ReadAnnotatedTag(ctx context.Context, repositoryDir, tag string) (Annotated
|
||||
if !validObjectID(object) {
|
||||
return AnnotatedTag{}, errors.New("invalid annotated tag object")
|
||||
}
|
||||
return ReadAnnotatedTagObject(ctx, repositoryDir, tag, object)
|
||||
}
|
||||
|
||||
// ReadAnnotatedTagObject verifies an explicitly recorded tag object even if
|
||||
// its local ref has already been removed.
|
||||
func ReadAnnotatedTagObject(ctx context.Context, repositoryDir, tag, object string) (AnnotatedTag, error) {
|
||||
if err := CheckTagRef(ctx, repositoryDir, tag); err != nil {
|
||||
return AnnotatedTag{}, err
|
||||
}
|
||||
if !validObjectID(object) {
|
||||
return AnnotatedTag{}, errors.New("invalid annotated tag object")
|
||||
}
|
||||
tagType, err := run(ctx, repositoryDir, nil, "cat-file", "-t", object)
|
||||
if err != nil {
|
||||
return AnnotatedTag{}, fmt.Errorf("inspect annotated tag: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user