Fix release destination handling and verification example
This commit is contained in:
@@ -108,7 +108,8 @@ func (f *releaseFixture) run(version, behavior, validatorAction string) (string,
|
||||
if [ "${CONFIGKIT_GIT_BEHAVIOR-}" = main-unknown ] || [ "${CONFIGKIT_GIT_BEHAVIOR-}" = tag-unknown ]; then
|
||||
if [ "${1-}" = ls-remote ] && [ -f "$CONFIGKIT_GIT_MARKER" ]; then exit 37; fi
|
||||
fi
|
||||
if [ "${1-}" = push ]; then
|
||||
case "$*" in
|
||||
push\ *|-c\ remote.origin.mirror=false\ push\ *)
|
||||
case "$*" in
|
||||
*refs/heads/main*)
|
||||
case "${CONFIGKIT_GIT_BEHAVIOR-}" in
|
||||
@@ -126,7 +127,8 @@ if [ "${1-}" = push ]; then
|
||||
tag-unknown) : > "$CONFIGKIT_GIT_MARKER"; exit 37 ;;
|
||||
esac ;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
exec "$CONFIGKIT_REAL_GIT" "$@"
|
||||
`
|
||||
if err := os.WriteFile(filepath.Join(bin, "git"), []byte(wrapper), 0700); err != nil {
|
||||
@@ -320,3 +322,38 @@ func TestReleasePublicationRecovery(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReleasePublicationUsesValidatedDestination(t *testing.T) {
|
||||
for _, behavior := range []string{"success", "main-lost", "tag-lost"} {
|
||||
t.Run(behavior, func(t *testing.T) {
|
||||
f := newReleaseFixture(t)
|
||||
other := filepath.Join(t.TempDir(), "other.git")
|
||||
f.git("init", "-q", "--bare", other)
|
||||
f.git("remote", "set-url", "--push", "origin", f.remote)
|
||||
f.git("config", "url."+other+".pushInsteadOf", f.remote)
|
||||
// These defaults must not broaden the explicit release refspecs when
|
||||
// publishing through the validated named remote.
|
||||
f.git("config", "remote.origin.mirror", "true")
|
||||
f.git("config", "remote.origin.push", "refs/heads/*:refs/heads/*")
|
||||
f.git("branch", "unrelated", f.base)
|
||||
f.git("tag", "-a", "-m", "Unrelated", "v0.8.0", f.base)
|
||||
f.git("--git-dir="+f.remote, "update-ref", "refs/heads/keep", f.base)
|
||||
|
||||
out, err := f.run("v0.9.0", behavior, "")
|
||||
if err != nil {
|
||||
t.Fatalf("publish: %v\n%s", err, out)
|
||||
}
|
||||
if f.validations() != 1 || f.remoteRef("refs/heads/main") != f.candidate ||
|
||||
f.remoteRef("refs/tags/v0.9.0") != f.git("rev-parse", "refs/tags/v0.9.0") {
|
||||
t.Fatal("publication did not reach the validated destination")
|
||||
}
|
||||
if f.remoteRef("refs/heads/keep") != f.base ||
|
||||
f.remoteRef("refs/heads/unrelated") != "" || f.remoteRef("refs/tags/v0.8.0") != "" {
|
||||
t.Fatal("publication changed unrelated refs")
|
||||
}
|
||||
if refs := f.git("--git-dir="+other, "for-each-ref", "--format=%(refname)"); refs != "" {
|
||||
t.Fatalf("publication reached the rewrite destination: %s", refs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user