Skip to content

Commit 4f944e2

Browse files
committed
cli/command/formatter: ContainerContext.Image: explicitly strip digest
The `reference.TrimNamed` function strips both digests and tags; the formatter function only wants to remove the digest, but preserve any tags present. Update the implementation to only trim the reference if there's a digest present, otherwise use it as-is. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 7ac3e0e commit 4f944e2

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

cli/command/formatter/container.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,22 @@ func (c *ContainerContext) Image() string {
181181
return c.c.Image
182182
}
183183

184-
if nt, ok := ref.(reference.NamedTagged); ok {
185-
// strip the digest, but preserve the tag
186-
if namedTagged, err := reference.WithTag(reference.TrimNamed(nt), nt.Tag()); err == nil {
187-
return reference.FamiliarString(namedTagged)
184+
if _, ok := ref.(reference.Digested); ok {
185+
// strip the digest, but preserve the tag (if any)
186+
var tag string
187+
if t, ok := ref.(reference.Tagged); ok {
188+
tag = t.Tag()
189+
}
190+
ref = reference.TrimNamed(ref)
191+
if tag != "" {
192+
if out, err := reference.WithTag(ref, tag); err == nil {
193+
ref = out
194+
}
188195
}
189-
} else {
190-
// case for when a tag is not provided
191-
named := reference.TrimNamed(ref)
192-
return reference.FamiliarString(named)
193196
}
194197

195-
return c.c.Image
198+
// Format as "familiar" name with "docker.io[/library]" trimmed.
199+
return reference.FamiliarString(ref)
196200
}
197201

198202
// Command returns's the container's command. If the trunc option is set, the

0 commit comments

Comments
 (0)