From 3a7faf7cf838586adab805ea3c2b65ac5ee9a079 Mon Sep 17 00:00:00 2001
From: Daniel J Walsh <dwalsh@redhat.com>
Date: Wed, 9 Sep 2020 06:44:10 -0400
Subject: [PATCH] Fix podman ps -l

Currently the --latest flag is ignored by podman ps command.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1877182

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
---
 pkg/domain/infra/abi/containers.go | 3 +++
 test/e2e/ps_test.go                | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 0537942e68..21618f5559 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -798,6 +798,9 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
 }
 
 func (ic *ContainerEngine) ContainerList(ctx context.Context, options entities.ContainerListOptions) ([]entities.ListContainer, error) {
+	if options.Latest {
+		options.Last = 1
+	}
 	return ps.GetContainerLists(ic.Libpod, options)
 }
 
diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go
index a734d399d4..a2338c924e 100644
--- a/test/e2e/ps_test.go
+++ b/test/e2e/ps_test.go
@@ -104,11 +104,13 @@ var _ = Describe("Podman ps", func() {
 		SkipIfRemote()
 		_, ec, _ := podmanTest.RunLsContainer("")
 		Expect(ec).To(Equal(0))
+		_, ec, _ = podmanTest.RunLsContainer("")
+		Expect(ec).To(Equal(0))
 
-		result := podmanTest.Podman([]string{"ps", "--latest"})
+		result := podmanTest.Podman([]string{"ps", "-q", "--latest"})
 		result.WaitWithDefaultTimeout()
 		Expect(result.ExitCode()).To(Equal(0))
-		Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0))
+		Expect(len(result.OutputToStringArray())).Should(Equal(1))
 	})
 
 	It("podman ps last flag", func() {