From 4788eb24abbdd747d978136d78ba8c2c2539c51a Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 30 Nov 2022 23:18:43 +0100 Subject: [PATCH] imagetools: set default repo ref on creation if nil Signed-off-by: CrazyMax --- commands/imagetools/create.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/commands/imagetools/create.go b/commands/imagetools/create.go index 2d86ffef685..3a7cf32ebe0 100644 --- a/commands/imagetools/create.go +++ b/commands/imagetools/create.go @@ -90,21 +90,24 @@ func runCreate(dockerCli command.Cli, in createOptions, args []string) error { } for i, s := range srcs { - if s.Ref == nil && s.Desc.MediaType == "" && s.Desc.Digest != "" { + if s.Ref == nil { if defaultRepo == nil { return errors.Errorf("multiple repositories specified, cannot infer repository for %q", args[i]) } - n, err := reference.ParseNormalizedNamed(*defaultRepo) if err != nil { return err } - r, err := reference.WithDigest(n, s.Desc.Digest) - if err != nil { - return err + if s.Desc.MediaType == "" && s.Desc.Digest != "" { + r, err := reference.WithDigest(n, s.Desc.Digest) + if err != nil { + return err + } + srcs[i].Ref = r + sourceRefs = true + } else { + srcs[i].Ref = reference.TagNameOnly(n) } - srcs[i].Ref = r - sourceRefs = true } }