diff --git a/cmd/oras/root/manifest/index/update.go b/cmd/oras/root/manifest/index/update.go index 16ab58518..145df88c4 100644 --- a/cmd/oras/root/manifest/index/update.go +++ b/cmd/oras/root/manifest/index/update.go @@ -67,6 +67,11 @@ Example - add one manifest from an index: } func updateIndex(cmd *cobra.Command, opts updateOptions) error { + // if --add is not used, then there's nothing to update + if !cmd.Flags().Changed("add") { + opts.Println("--add is not used. There's nothing to update.") + return nil + } ctx, logger := command.GetLogger(cmd, &opts.Common) target, err := opts.NewTarget(opts.Common, logger) if err != nil { diff --git a/test/e2e/suite/command/manifest_index.go b/test/e2e/suite/command/manifest_index.go index ba47b0263..5344fe4c7 100644 --- a/test/e2e/suite/command/manifest_index.go +++ b/test/e2e/suite/command/manifest_index.go @@ -119,7 +119,7 @@ var _ = Describe("1.1 registry users:", func() { ORAS("manifest", "fetch", RegistryRef(ZOTHost, ImageRepo, "update-add")). MatchKeyWords("amd64", "arm64", "v7").Exec() }) - It("should update by specifying index digest", func() { + It("should update by specifying the index digest", func() { // create an index for testing purpose ORAS("manifest", "index", "create", RegistryRef(ZOTHost, ImageRepo, ""), string(multi_arch.LinuxAMD64.Digest), string(multi_arch.LinuxARM64.Digest)).Exec() @@ -131,6 +131,10 @@ var _ = Describe("1.1 registry users:", func() { ORAS("manifest", "fetch", RegistryRef(ZOTHost, ImageRepo, "sha256:84887718c9e61daa0f1996aad3ae2eb10db15dcbdab394e4b2dfee7967c55f2c")). MatchKeyWords("amd64", "arm64", "v7").Exec() }) + It("should tell user nothing to update if no update flags are used", func() { + ORAS("manifest", "index", "update", RegistryRef(ZOTHost, ImageRepo, "nothing-to-update")). + MatchKeyWords("nothing to update").Exec() + }) It("should fail if empty reference is given", func() { ORAS("manifest", "index", "update", RegistryRef(ZOTHost, ImageRepo, ""), "--add", string(multi_arch.LinuxARMV7.Digest)).ExpectFailure().