Skip to content

basic support for --keep-git-dir, --unpack, --parents#106

Merged
m-ildefons merged 2 commits into
hadolint:masterfrom
aokellermann:aokellermann/pr
Jun 24, 2026
Merged

basic support for --keep-git-dir, --unpack, --parents#106
m-ildefons merged 2 commits into
hadolint:masterfrom
aokellermann:aokellermann/pr

Conversation

@aokellermann

Copy link
Copy Markdown
Contributor

@rene

rene commented Apr 28, 2026

Copy link
Copy Markdown

Dear maintainers, this issue has been impacting EVE-OS project for a while, any chances to get this PR merged?

https://github.com/lf-edge/eve/pull/5839/changes#diff-388d69413dd217e9bd38afa91aa10c32a35fa8f76f91b8b71e85eb8d7116b0c0R18

@aokellermann

Copy link
Copy Markdown
Contributor Author

just rebased with Claude.

pinging @m-ildefons

@m-ildefons m-ildefons left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.
It's just not quite there yet: there are missing test cases and the parser doesn't really model what the syntax reference specifies for the two flags.

Comment thread src/Language/Docker/Parser/Copy.hs Outdated
parents :: Parser Parents
parents = do
void $ string "--parents"
return Parents

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag optionally takes an explicit boolean value, i.e. the following three variations are all valid syntax:

COPY --parents foo bar
COPY --parents=true foo bar
COPY --parents=false foo bar

This parser only supports the first case, but would fail to correctly work for the other two cases.

https://docs.docker.com/reference/dockerfile/#copy---parents

Comment thread src/Language/Docker/Parser/Copy.hs Outdated
Comment on lines +187 to +190
keepGitDir :: Parser KeepGitDir
keepGitDir = do
void $ string "--keep-git-dir"
return KeepGitDir

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag takes an obligatory boolean value, much like the --unpack flag.
This parser doesn't accept that.

https://docs.docker.com/reference/dockerfile/#add---unpack

Comment on lines +163 to +167
prettyPrintKeepGitDir :: KeepGitDir -> Doc ann
prettyPrintKeepGitDir keepGitDir =
case keepGitDir of
KeepGitDir -> "--keep-git-dir"
NoKeepGitDir -> mempty

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should either produce --keep-git-dir=true, --keep-git-dir=false or nothing, since the boolean value for the flag is not optional.

Comment on lines +170 to +173
data Parents
= Parents
| NoParents
deriving (Show, Eq, Ord)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This datastructure doesn't accurately model the --parents flag. It should be more like the data structure Unpack below, because that allows a distinction between the absence of the flag and an explicit --parents=false. The distinction is important to be able to make the pretty printer either omit the flag, or produce an explicit --parents=false.

Comment thread test/Language/Docker/ParseAddSpec.hs Outdated
Comment on lines +76 to +82
it "with keep-git-dir flag" $
let file = Text.unlines ["ADD --keep-git-dir foo bar"]
in assertAst
file
[ Add
( AddArgs (fmap SourcePath ["foo"]) (TargetPath "bar") )
( AddFlags NoChecksum NoChown NoChmod NoLink KeepGitDir NoUnpack [] )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test cases for --keep-git-dir=true and --keep-git-dir=false

Comment thread test/Language/Docker/ParseCopySpec.hs Outdated
Comment on lines +89 to +95
it "with parents flag" $
let file = Text.unlines [ "COPY --parents source /target" ]
in assertAst
file
[ Copy
( CopyArgs [ SourcePath "source" ] ( TargetPath "/target" ) )
( CopyFlags NoChown NoChmod NoLink Parents NoSource [])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test cases for --parents=true and --parents=false

Comment thread test/Language/Docker/PrettyPrintSpec.hs Outdated
Comment on lines +45 to +49
it "with just keep-git-dir" $ do
let add = Add
( AddArgs [SourcePath "foo"] (TargetPath "bar") )
( AddFlags NoChecksum NoChown NoChmod NoLink KeepGitDir NoUnpack [] )
in assertPretty "ADD --keep-git-dir foo bar" add

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test cases for --keep-git-dir=true and --keep-git-dir=false

Comment thread test/Language/Docker/PrettyPrintSpec.hs Outdated
Comment on lines +107 to +111
it "with just parents" $ do
let copy = Copy
( CopyArgs [SourcePath "foo"] (TargetPath "bar") )
( CopyFlags NoChown NoChmod NoLink Parents NoSource [] )
in assertPretty "COPY --parents foo bar" copy

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test cases for --parents=true and --parents=false

Add explicit and implicit versions for --unpack, --parents and
--keep-git-dir flags.
This means that

COPY --unpack foo bar

and

COPY --unpack=true foo bar

are now equivalent and both valid.
Similarly for --parents and --keep-git-dir flags as well.

Signed-off-by: Moritz Röhrich <moritz@ildefons.de>
@m-ildefons
m-ildefons merged commit 51d8ca8 into hadolint:master Jun 24, 2026
2 checks passed
@m-ildefons

Copy link
Copy Markdown
Member

Again, thanks for the PR. I've gone ahead and fixed it up a bit, so it supports both the explicit and the implicit versions of these flags, i.e. --parents and --parents=true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants