Skip to content

Commit

Permalink
fix: reference in the formatted output of oras pull is invalid (#1496)
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 authored Sep 9, 2024
1 parent 40dd8f9 commit 70ac79b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
22 changes: 4 additions & 18 deletions cmd/oras/internal/option/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/suite/command/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 70ac79b

Please sign in to comment.