Skip to content

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

Open
aokellermann wants to merge 1 commit intohadolint:masterfrom
aokellermann:aokellermann/pr
Open

basic support for --keep-git-dir, --unpack, --parents#106
aokellermann wants to merge 1 commit intohadolint:masterfrom
aokellermann:aokellermann/pr

Conversation

@aokellermann
Copy link
Copy Markdown

@rene
Copy link
Copy Markdown

rene commented Apr 28, 2026

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
Author

just rebased with Claude.

pinging @m-ildefons

Copy link
Copy Markdown
Member

@m-ildefons m-ildefons left a comment

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.

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 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 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 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 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 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

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