diff --git a/libimage/history.go b/libimage/history.go index 46252df10..ad989b528 100644 --- a/libimage/history.go +++ b/libimage/history.go @@ -51,7 +51,6 @@ func (i *Image) History(ctx context.Context) ([]ImageHistory, error) { } if layer != nil { - history.Tags = layer.Names if !ociImage.History[x].EmptyLayer { history.Size = layer.UncompressedSize } @@ -64,8 +63,13 @@ func (i *Image) History(ctx context.Context) ([]ImageHistory, error) { history.ID = id usedIDs[id] = true } + for i := range node.images { + history.Tags = append(history.Tags, node.images[i].Names()...) + } } - if layer.Parent != "" && !ociImage.History[x].EmptyLayer { + if layer.Parent == "" { + layer = nil + } else if !ociImage.History[x].EmptyLayer { layer, err = i.runtime.store.Layer(layer.Parent) if err != nil { return nil, err diff --git a/libimage/history_test.go b/libimage/history_test.go new file mode 100644 index 000000000..97484acfd --- /dev/null +++ b/libimage/history_test.go @@ -0,0 +1,28 @@ +package libimage + +import ( + "context" + "testing" + + "github.com/containers/common/pkg/config" + "github.com/stretchr/testify/require" +) + +func TestHistory(t *testing.T) { + runtime, cleanup := testNewRuntime(t) + defer cleanup() + ctx := context.Background() + + name := "quay.io/libpod/alpine:3.10.2" + pullOptions := &PullOptions{} + pulledImages, err := runtime.Pull(ctx, name, config.PullPolicyAlways, pullOptions) + require.NoError(t, err) + require.Len(t, pulledImages, 1) + + history, err := pulledImages[0].History(ctx) + require.NoError(t, err) + require.Len(t, history, 2) + + require.Equal(t, []string{name}, history[0].Tags) + require.Len(t, history[1].Tags, 0) +}