Skip to content

Commit

Permalink
Merge pull request #1441 from crazy-max/fix-nil-ref
Browse files Browse the repository at this point in the history
imagetools: set default repo ref on creation if nil
  • Loading branch information
tonistiigi authored Dec 1, 2022
2 parents 3ed2783 + 4788eb2 commit e91d532
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions commands/imagetools/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit e91d532

Please sign in to comment.