imagetools: set default repo ref on creation if nil

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-11-30 23:18:43 +01:00
parent 3ed2783f34
commit 4788eb24ab
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
1 changed files with 10 additions and 7 deletions

View File

@ -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
}
}