Treat incomplete remote tag observations as uncertain
This commit is contained in:
@@ -36,6 +36,64 @@ func TestVersionCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishCommandReportsUnknownForPeeledOnlyRecovery(t *testing.T) {
|
||||
repository := newCLIRepository(t)
|
||||
writeRepositoryFile(t, repository, "docs/releases/v1.2.3.md", "# Example Product v1.2.3\n\nRelease note.\n")
|
||||
profile, err := json.Marshal(cli.Settings{Product: "Example Product", Remote: "origin"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writeRepositoryFile(t, repository, "releasekit.json", string(profile))
|
||||
cliGitRun(t, repository, "add", "docs/releases/v1.2.3.md", "releasekit.json")
|
||||
cliGitRun(t, repository, "commit", "-m", "configure release")
|
||||
remote := filepath.Join(t.TempDir(), "origin.git")
|
||||
cliGitRun(t, repository, "init", "--bare", remote)
|
||||
cliGitRun(t, repository, "remote", "add", "origin", remote)
|
||||
cliGitRun(t, repository, "push", "--set-upstream", "origin", "main")
|
||||
realGit, err := exec.LookPath("git")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bin := t.TempDir()
|
||||
marker := filepath.Join(t.TempDir(), "pushed")
|
||||
script := `#!/bin/sh
|
||||
is_push=0
|
||||
is_ls=0
|
||||
for arg in "$@"; do
|
||||
[ "$arg" = push ] && is_push=1
|
||||
[ "$arg" = ls-remote ] && is_ls=1
|
||||
done
|
||||
if [ "$is_ls" = 1 ] && [ -f "$PUSH_MARKER" ]; then
|
||||
case " $* " in *refs/tags/v1.2.3*)
|
||||
object=$("$REAL_GIT" rev-parse 'refs/tags/v1.2.3^{}')
|
||||
printf '%s\trefs/tags/v1.2.3^{}\n' "$object"
|
||||
exit 0;; esac
|
||||
fi
|
||||
if [ "$is_push" = 1 ]; then
|
||||
"$REAL_GIT" "$@" || exit $?
|
||||
: > "$PUSH_MARKER"
|
||||
echo 'lost acknowledgment' >&2
|
||||
exit 77
|
||||
fi
|
||||
exec "$REAL_GIT" "$@"
|
||||
`
|
||||
if err := os.WriteFile(filepath.Join(bin, "git"), []byte(script), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
|
||||
t.Setenv("REAL_GIT", realGit)
|
||||
t.Setenv("PUSH_MARKER", marker)
|
||||
var stdout, stderr bytes.Buffer
|
||||
status := run(context.Background(), []string{"publish", "--repo", repository, "v1.2.3"}, &stdout, &stderr)
|
||||
if status != 3 || !strings.Contains(stderr.String(), "unknown") || strings.Contains(stdout.String(), "published") {
|
||||
t.Fatalf("status = %d, stdout = %q, stderr = %q", status, stdout.String(), stderr.String())
|
||||
}
|
||||
local := cliGitOutput(t, repository, "rev-parse", "refs/tags/v1.2.3")
|
||||
if got := cliGitOutput(t, remote, "rev-parse", "refs/tags/v1.2.3"); got != local {
|
||||
t.Fatalf("remote tag = %s, want %s", got, local)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnknownCommand(t *testing.T) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
if status := run(context.Background(), []string{"unknown"}, &stdout, &stderr); status != 2 {
|
||||
|
||||
Reference in New Issue
Block a user