diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index b81c52b26..489eeb820 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -113,6 +113,8 @@ func (opts *Target) Parse(cmd *cobra.Command) error { } } else { opts.Reference = ref.Reference + ref.Reference = "" + opts.Path = ref.String() } return opts.Remote.Parse(cmd) } @@ -145,15 +147,7 @@ func (opts *Target) newOCIStore() (*oci.Store, error) { } func (opts *Target) newRepository(common Common, logger logrus.FieldLogger) (*remote.Repository, error) { - repo, err := opts.NewRepository(opts.RawReference, common, logger) - if err != nil { - return nil, err - } - tmp := repo.Reference - tmp.Reference = "" - opts.Path = tmp.String() - opts.Reference = repo.Reference.Reference - return repo, nil + return opts.NewRepository(opts.RawReference, common, logger) } // NewTarget generates a new target based on opts. @@ -232,15 +226,7 @@ func (opts *Target) NewReadonlyTarget(ctx context.Context, common Common, logger } return store, nil case TargetTypeRemote: - repo, err := opts.NewRepository(opts.RawReference, common, logger) - if err != nil { - return nil, err - } - tmp := repo.Reference - tmp.Reference = "" - opts.Path = tmp.String() - opts.Reference = repo.Reference.Reference - return repo, nil + return opts.NewRepository(opts.RawReference, common, logger) } return nil, fmt.Errorf("unknown target type: %q", opts.Type) } diff --git a/test/e2e/suite/command/pull.go b/test/e2e/suite/command/pull.go index cb9e7a666..d463cf582 100644 --- a/test/e2e/suite/command/pull.go +++ b/test/e2e/suite/command/pull.go @@ -267,6 +267,13 @@ var _ = Describe("OCI spec 1.1 registry users:", func() { Expect(err).ShouldNot(HaveOccurred()) }) + It("should show correct reference", func() { + tempDir := PrepareTempFiles() + ref := RegistryRef(ZOTHost, ArtifactRepo, foobar.Tag) + out := ORAS("pull", ref, "--format", "go-template={{.reference}}").WithWorkDir(tempDir).Exec().Out.Contents() + Expect(out).To(Equal([]byte("localhost:7000/command/artifacts@sha256:fd6ed2f36b5465244d5dc86cb4e7df0ab8a9d24adc57825099f522fe009a22bb"))) + }) + It("should pull specific platform", func() { ORAS("pull", RegistryRef(ZOTHost, ImageRepo, "multi"), "--platform", "linux/amd64", "-v", "-o", GinkgoT().TempDir()). MatchStatus(multi_arch.LinuxAMD64StateKeys, true, len(multi_arch.LinuxAMD64StateKeys)).Exec()