Merge pull request #3395 from adrianreber/diff

Add --latest, -l to 'podman diff'
This commit is contained in:
OpenShift Merge Robot
2019-06-21 16:15:00 +02:00
committed by GitHub
3 changed files with 28 additions and 2 deletions

View File

@ -113,6 +113,7 @@ type DiffValues struct {
PodmanCommand PodmanCommand
Archive bool Archive bool
Format string Format string
Latest bool
} }
type ExecValues struct { type ExecValues struct {

View File

@ -60,8 +60,10 @@ func init() {
flags.BoolVar(&diffCommand.Archive, "archive", true, "Save the diff as a tar archive") flags.BoolVar(&diffCommand.Archive, "archive", true, "Save the diff as a tar archive")
flags.StringVar(&diffCommand.Format, "format", "", "Change the output format") flags.StringVar(&diffCommand.Format, "format", "", "Change the output format")
flags.BoolVarP(&diffCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.MarkHidden("archive") flags.MarkHidden("archive")
markFlagHiddenForRemoteClient("latest", flags)
} }
@ -83,7 +85,7 @@ func formatJSON(output []diffOutputParams) (diffJSONOutput, error) {
} }
func diffCmd(c *cliconfig.DiffValues) error { func diffCmd(c *cliconfig.DiffValues) error {
if len(c.InputArgs) != 1 { if len(c.InputArgs) != 1 && !c.Latest {
return errors.Errorf("container, image, or layer name must be specified: podman diff [options [...]] ID-NAME") return errors.Errorf("container, image, or layer name must be specified: podman diff [options [...]] ID-NAME")
} }
@ -93,7 +95,16 @@ func diffCmd(c *cliconfig.DiffValues) error {
} }
defer runtime.Shutdown(false) defer runtime.Shutdown(false)
to := c.InputArgs[0] var to string
if c.Latest {
ctr, err := runtime.GetLatestContainer()
if err != nil {
return errors.Wrapf(err, "unable to get latest container")
}
to = ctr.ID()
} else {
to = c.InputArgs[0]
}
changes, err := runtime.Diff(c, to) changes, err := runtime.Diff(c, to)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get changes for %q", to) return errors.Wrapf(err, "could not get changes for %q", to)

View File

@ -80,4 +80,18 @@ var _ = Describe("Podman diff", func() {
sort.Strings(imageDiff) sort.Strings(imageDiff)
Expect(imageDiff).To(Equal(containerDiff)) Expect(imageDiff).To(Equal(containerDiff))
}) })
It("podman diff latest container", func() {
SkipIfRemote()
session := podmanTest.Podman([]string{"run", "--name=diff-test", ALPINE, "touch", "/tmp/diff-test"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"diff", "-l"})
session.WaitWithDefaultTimeout()
containerDiff := session.OutputToStringArray()
sort.Strings(containerDiff)
Expect(session.LineInOutputContains("C /tmp")).To(BeTrue())
Expect(session.LineInOutputContains("A /tmp/diff-test")).To(BeTrue())
Expect(session.ExitCode()).To(Equal(0))
})
}) })